-
Notifications
You must be signed in to change notification settings - Fork 23
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
Sanitize filenames and handle member issues in attendance.py
example script
#155
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d8c67a8
Add Excel folder to .gitignore
alsp80 ff7d1c2
Merge pull request #1 from Olen/main
alsp80 f7fb4aa
Handle filenames better and don't exit if a member does not exist
alsp80 42e8695
Revert "Add Excel folder to .gitignore"
elliot-100 970f190
Merge remote-tracking branch 'upstream/main'
elliot-100 68c7820
Format with black
elliot-100 8984e69
Refactor: extract `_sanitise_chars()`
elliot-100 5221e0e
Revert "Refactor: extract `_sanitise_chars()`"
elliot-100 4edc771
Refactor: extract `_sanitise_filename()`
elliot-100 20ae96c
Refactor: extract duplicated code
elliot-100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,7 @@ cython_debug/ | |
# Project specific | ||
exports/* | ||
config.py | ||
Excel/* | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import asyncio | ||
import csv | ||
import os | ||
import re | ||
from datetime import date | ||
|
||
from config import password, username | ||
|
@@ -38,8 +39,11 @@ async def main(): | |
os.makedirs("./exports") | ||
|
||
for e in events: | ||
filename = f"{e['startTimestamp']}-{e['heading']}.csv" | ||
filename = str(filename).strip().replace(" ", "_") | ||
filename = re.sub(r"(?u)[^-\w.]", "", filename) | ||
filename = os.path.join( | ||
"./exports", f"{e['startTimestamp']}-{e['heading']}.csv" | ||
"./exports", filename | ||
) | ||
with open(filename, "w", newline="") as csvfile: | ||
spamwriter = csv.writer( | ||
|
@@ -50,8 +54,12 @@ async def main(): | |
["Start", "End", "Description", "Name", "Answer", "Organizer"] | ||
) | ||
for o in e["owners"]: | ||
person = await s.get_person(o["id"]) | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
try: | ||
person = await s.get_person(o["id"]) | ||
except KeyError: | ||
full_name = o["id"] | ||
else: | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommend refactoring out this repeated line to a function e.g. |
||
spamwriter.writerow( | ||
[ | ||
e["startTimestamp"], | ||
|
@@ -64,8 +72,12 @@ async def main(): | |
) | ||
if args.a is True: | ||
for r in e["responses"]["acceptedIds"]: | ||
person = await s.get_person(r) | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ..and this repeated block too. |
||
person = await s.get_person(r) | ||
except KeyError: | ||
full_name = r | ||
else: | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
spamwriter.writerow( | ||
[ | ||
e["startTimestamp"], | ||
|
@@ -76,8 +88,12 @@ async def main(): | |
] | ||
) | ||
for r in e["responses"]["declinedIds"]: | ||
person = await s.get_person(r) | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
try: | ||
person = await s.get_person(r) | ||
except KeyError: | ||
full_name = r | ||
else: | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
spamwriter.writerow( | ||
[ | ||
e["startTimestamp"], | ||
|
@@ -88,8 +104,12 @@ async def main(): | |
] | ||
) | ||
for r in e["responses"]["unansweredIds"]: | ||
person = await s.get_person(r) | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
try: | ||
person = await s.get_person(r) | ||
except KeyError: | ||
full_name = r | ||
else: | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
spamwriter.writerow( | ||
[ | ||
e["startTimestamp"], | ||
|
@@ -100,8 +120,12 @@ async def main(): | |
] | ||
) | ||
for r in e["responses"]["unconfirmedIds"]: | ||
person = await s.get_person(r) | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
try: | ||
person = await s.get_person(r) | ||
except KeyError: | ||
full_name = r | ||
else: | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
spamwriter.writerow( | ||
[ | ||
e["startTimestamp"], | ||
|
@@ -112,8 +136,12 @@ async def main(): | |
] | ||
) | ||
for r in e["responses"]["waitinglistIds"]: | ||
person = await s.get_person(r) | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
try: | ||
person = await s.get_person(r) | ||
except KeyError: | ||
full_name = r | ||
else: | ||
full_name = person["firstName"] + " " + person["lastName"] | ||
spamwriter.writerow( | ||
[ | ||
e["startTimestamp"], | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to refactor out the filename-derivation code into a self-documenting function, e.g.
sanitised_filename(event)
.