Error while generating PDF file from a group chat
Hello,
The script seems to have issues with generating plots from group chats. It works fine with private conversations, but I get this whenever I try to generate one from a chat with many people in it:
==================================== Plots =====================================
Traceback (most recent call last):
File "C:\Users\zzubo\Desktop\fb\FacebookChatStatistics-master\facebook_chat_statistics.py", line 187, in <module>
main()
File "C:\Users\zzubo\Desktop\fb\FacebookChatStatistics-master\facebook_chat_statistics.py", line 61, in main
with PdfPages(filename) as pdf:
File "C:\Users\zzubo\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\backends\backend_pdf.py", line 2686, in __init__
self._file = PdfFile(filename, metadata=metadata)
File "C:\Users\zzubo\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\backends\backend_pdf.py", line 654, in __init__
fh, opened = cbook.to_filehandle(filename, "wb", return_opened=True)
File "C:\Users\zzubo\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\cbook\__init__.py", line 451, in to_filehandle
fh = open(fname, flag, encoding=encoding)
OSError: [Errno 22] Invalid argument: 'xxx_20210819_20211214.pdf'
xxx being list of names of people in said group chat. Is there a quick fix I could do myself? I'm not knowledgeable at all in python. Thanks!
Upon editing the script (making filename equal to some random letters in line 57) it works, however activity per day, activity per week and top 10 emojis plots aren't generating. They're just empty graphs.
Hello,
Thanks for bringing this to my attention! I will have a look at it and get back to you.
Hello again,
I'm not able to recreate your errors, but I did find some other bugs that should be fixed now.
To me it sounds like the code is not able to handle the names of the participants in the conversation. Does any name contain any special characters, and if so, which?
Many names do contain Polish characters (ą, ę, ó, ł, ż, ź, ś, ć, ń) as well as some cyrillic, however those shouldn't be an issue as I am able to generate the plots with all of the participants separately. I think the issue is that the filename of the file your script is trying to generate is 300 characters long, and a quick google search reveals the limit (including the path to the file) is 255.
New update improved the timeline graph, which is awesome, however the other three graphs are still empty. Maybe facebook changed something in the way they store the details of the conversation?
Thank you kindly for your quick response and for your time put into this issue!
Many names do contain Polish characters (ą, ę, ó, ł, ż, ź, ś, ć, ń) as well as some cyrillic, however those shouldn't be an issue as I am able to generate the plots with all of the participants separately. I think the issue is that the filename of the file your script is trying to generate is 300 characters long, and a quick google search reveals the limit (including the path to the file) is 255.
New update improved the timeline graph, which is awesome, however the other three graphs are still empty. Maybe facebook changed something in the way they store the details of the conversation?
Thank you kindly for your quick response and for your time put into this issue!
The recent update includes code to handle long filenames by limiting them to 255 characters, so this should no longer be an issue. I used newly downloaded data from Facebook when working on this earlier today, so that should not be the issue either. To debug the problem further I recommend you to print the lists to the terminal by e.g. writing print(nbr_times_hour) to see if they look reasonable or not (i.e. not empty or just containing zeros).
And I assume that you don't get any other error and that the code reaches the line where it prints PDF generated successfully!, correct?
You are correct, I attempted to generate statistics from the group chat with the old version of the script, there is no more issue with generating group chat pdfs.
I actually do get errors before "PDF generated successfully!", but I omitted mentioning it since they're all userwarnings informing me there's glyphs (all emojis) 'missing from the current font', and assumed it wouldn't affect anything besides the last graph with emojis (which I didn't need for my purposes anyways).
I am not sure where to include print(nbr_times_hour), if you could explain this further it would be greatly appreciated.
Ok, great. The code that handles the emojis is a bit wonky and is in need of an update... But yeah, the other graphs should still work.
After line 85 in facebook_chat_statistics.py where the timeline() function is called you could write
print(nbr_times_day)
print(nbr_times_weekday)
print(nbr_times_hour)
in order to print those three lists to your terminal.
I have done that, the lists seem reasonable, there's no zeroes nor are there empty slots. This is what it spits out:
[17, 7, 13, 9, 17, 13, 20, 14, 13, 8, 7, 11, 6, 7, 7, 6, 8, 7, 7, 7, 6, 6, 6, 10, 7, 6, 9, 9, 12, 4, 8, 8, 5, 9, 5, 3, 6, 3, 5, 2, 2, 6, 2, 2, 5, 9, 3, 7, 17, 15, 13, 15, 14, 12, 12, 13, 14, 15, 9, 13, 7, 9, 5, 14, 5, 9, 15, 6, 10, 10, 10, 6, 5, 10, 8, 11, 8, 8, 4, 6, 8, 10, 6, 4, 6, 7, 7, 7, 5, 6, 9, 7, 7, 9, 7, 4, 8, 7, 9, 7, 8, 9, 10, 9, 5, 14, 5, 4, 7, 7, 6, 9, 10, 8, 5, 4, 2, 6] [122, 135, 140, 168, 121, 132, 146] [20, 22, 13, 14, 5, 2, 5, 9, 31, 24, 66, 89, 55, 65, 65, 64, 71, 68, 79, 63, 44, 36, 31, 23]
Here's a screenshot of what it generates, in case it helps in any way. https://i.imgur.com/Dgh9tyE.png