Skip to content
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

Datasette-lite this... #11

Closed
ross-spencer opened this issue Feb 1, 2023 · 6 comments
Closed

Datasette-lite this... #11

ross-spencer opened this issue Feb 1, 2023 · 6 comments

Comments

@ross-spencer
Copy link
Member

I have been working with Datasette-lite this week, and I would be exceptionally easy to convert this data to Datasette. (Actually it may simply just work from the CSV...) 🤔

@ross-spencer
Copy link
Member Author

Related to: nasawakeupcalls/nasawakeupcalls.data#25

@ross-spencer
Copy link
Member Author

CSV quoting code:

"""Simple script to force-quote an existing CSV file as Sheets, and
Excel doesn't already do this. LibreOffice I believe does.
"""
import csv

data = []
header = None

with open("nasawakeupcalls.csv", "r", encoding="utf8") as nasa_csv:
    csv_reader = csv.reader(nasa_csv, delimiter=",")
    header = next(csv_reader, None)
    # The remainder of the rows are data rows.
    for row in csv_reader:
        assert len(row) == len(
            header
        ), "Problem parsing rows, inequal lenghts: {} (header) vs. {} (row)".format(
            len(row), len(header)
        )
        data_dict = dict(zip(header, row))
        data.append(data_dict)

with open("quoted_nasawakeupcalls.csv", "wt", newline="") as new_csv:
    writer = csv.DictWriter(
        new_csv, fieldnames=header, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL
    )
    writer.writeheader()
    for idx, row in enumerate(data):
        if not row:
            continue
        writer.writerow(row)

@ross-spencer
Copy link
Member Author

Useful tool from SimonW:

@ross-spencer
Copy link
Member Author

Deployed to: https://nasawakeupcalls.github.io/datasette

@ross-spencer
Copy link
Member Author

Linked to here as well: https://nasawakeupcalls.github.io/data/

Okay, I think this is done for now. We may look at datasette and think we can do more with the field types, and datasette may include more plugins as well. These can be registered as new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant