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

Sanitize filenames and handle member issues in attendance.py example script #155

Merged
merged 10 commits into from
Oct 20, 2024

Conversation

alsp80
Copy link
Contributor

@alsp80 alsp80 commented Oct 1, 2024

Hi,

I came across two issues when using your project. One is about sanitising filenames based on events (for attendance) where certain special characters allowed by Spond in event names (e.g. a forward slash) would lead to unexpected behaviour or problems. I've added some code to handle these (however this might need to be reviewed for copyright as I found it somewhere but it was mentioned that it might have been taken from Django).

The other change is to handle the situation when member information is not available which lead to a crash. I'm not sure what is wrong in the account on Spond but I've included some handling for the situation when the member based on ID cannot be found. In that case the output will simply be the member guid.

The last (or actually first) commit (adding a folder into .gitignore) can probably be ignored, however I did not manage to exclude it from the Pull Request. Seems I need to beef up my git skills.

Hope some of it is useful, thanks for sharing your project, it has helped me already and I might add additional functionality and send more pull requests if ok for you.

Thanks,
Alex

@Olen
Copy link
Owner

Olen commented Oct 1, 2024

Hi, and thanks for your effort.

Ideally, this should have been two PRs, but I totally understand you.
Regarding the Excel folder, as long as you don't git add Excel/ it should not be added, but I have no problem with the gitignore.

The filename-sanitising is fine. Even if you found it somewhere, it looks so generic that I can't see any copyright problems, even if you did not invent the exact code yourself, It could also be that somene else here have a few comments, and maybe also have other changes they might want to add to it, so I'll leave that for now.

I'll let others also have a look at it, but at first glance, it looks fine to me.

attendance.py Outdated
@@ -38,8 +39,11 @@ async def main():
os.makedirs("./exports")

for e in events:
filename = f"{e['startTimestamp']}-{e['heading']}.csv"
Copy link
Collaborator

@elliot-100 elliot-100 Oct 2, 2024

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).

attendance.py Outdated
except KeyError:
full_name = o["id"]
else:
full_name = person["firstName"] + " " + person["lastName"]
Copy link
Collaborator

@elliot-100 elliot-100 Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend refactoring out this repeated line to a function e.g. full_name(person).

attendance.py Outdated
@@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..and this repeated block too.

@elliot-100
Copy link
Collaborator

elliot-100 commented Oct 2, 2024

Hi - thanks for the PR! I have made a couple of comments on the code and have a couple more general points:

  • It would be good to add a comment at the top of the file summarising what it does.

  • The checks are failing - it looks like you have trailing whitespace. Can you run black . to auto-format please?

Edit: I've gone ahead and reverted the .gitignore change as it isn't relevant to the rest of the PR as it stands now - the exports directory is already ignored.

@elliot-100 elliot-100 changed the title Sanitize filenames and handle member issues Sanitize filenames and handle member issues in attendance.py example script Oct 2, 2024
@elliot-100
Copy link
Collaborator

Hey @alsp80 - I hope I didn't put you off?

I'm happy to assist or resolve any of these points. Let us know... thanks again!

@elliot-100 elliot-100 marked this pull request as draft October 20, 2024 11:12
@elliot-100 elliot-100 marked this pull request as ready for review October 20, 2024 13:17
@elliot-100 elliot-100 merged commit d70399f into Olen:main Oct 20, 2024
5 checks passed
@elliot-100
Copy link
Collaborator

elliot-100 commented Oct 20, 2024

Thanks again @alsp80, merged!

I did do a couple of simple refactors. (I did notice some pre-existing issues here, e.g. 'organiser' column actually contains organisers or members if you use the -a flag, but that's one for another PR. Also I don't think the file handling in aync context is best practice).

Could you let me know if all is OK with the changes and raise a new Bug issue if not? Thanks.

@elliot-100 elliot-100 added the enhancement New feature or request label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants