Skip to content

adding class reader example #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

adding class reader example #19

wants to merge 2 commits into from

Conversation

jposada202020
Copy link
Contributor

Adding an example to show how to read csv files from the disk.
had to hack a little the results as I was having some trouble with the regex.

Thanks :)

@tekktrik tekktrik self-requested a review February 15, 2023 03:50
@tekktrik
Copy link
Owner

I think I need to update the CI before running the tests, so if you don't mind I'll do those changes and merge them into your PR on your behalf if that's okay.

@jposada202020
Copy link
Contributor Author

No problem at all :) . Cheers

@tekktrik
Copy link
Owner

Looks like you need to specify an encoding argument when using open(). Setting it to utf-8 should resolve the issue.

@jposada202020
Copy link
Contributor Author

I modified the open,

with open(weather_file,  "r", encoding="utf-8") as csvfile:
    row = csv.reader(csvfile)
    for item in row:
        raw_data.append(item[11])
print(raw_data[0:41])

and I get this. The header and the data does not seem to match.

Adafruit CircuitPython 8.0.0 on 2023-02-06; Adafruit PyPortal Titano with samd51j20
>>> import csr
Setting up SD Card
Reading the csv file contents. This could take some time
['Min Temp (°C)', '","19.6', '","21.2', '","25.6', '","27.7', '","31.5', '","32.6', '","28.9', '","28.0', '","22.5', '","20.6', '","17.6', '","22.0', '","31.3', '","22.1', '","19.7', '","20.7', '","20.0', '","23.4', '","26.9', '","30.4', '","24.2', '","24.5', '","27.2', '","25.6', '","28.9', '","33.9', '","28.9', '","36.9', '","40.6', '","41.3', '","39.7', '","39.0', '","37.1', '","41.3', '","30.8', '","33.0', '","28.9', '","25.0', '","24.6', '","19.4']
Done reading
Now we will display the data

@tekktrik
Copy link
Owner

Did you have the issue before adding the encoding? I'm not surprised the quotes are messing it up, I guess it's still an issue for the library.

@jposada202020
Copy link
Contributor Author

Yes same issue, guessing is the regex, but I am not good enough at regex to be 100% sure.

@tekktrik
Copy link
Owner

Yeah, the regex is easy to anger. It's something I'd love to revisit, the quote character is very finicky. In the meantime, it may be worth finding a simpler example, since I do like the idea of documenting the feature!

@jposada202020
Copy link
Contributor Author

Simple ... yes.. I think about something.... I did this for Fakerequests, but I would not consider this "simple" LOL
adafruit/Adafruit_CircuitPython_FakeRequests#4

Simplest thing will be to read something that is written.. but Ideas are welcome :)

Things that we have tought
List of colors -
List of values
Stock market - Discarded for Copyright issues
Slide show

Let me know :)

@jposada202020 jposada202020 deleted the adding_reader_example branch February 17, 2023 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants