3 ms·
The scripts are pretty messy, but the process went like this. It was necessary to use AppleScript because the Graph API doesn't give access to friend's Likes (b
by peterburkimsher 9y ago
The scripts are pretty messy, but the process went like this. It was necessary to use AppleScript because the Graph API doesn't give access to friend's Likes (because of privacy issues e.g. Cambridge Analytica). But AppleScript has access to everything through the GUI. (if anyone from Facebook reads this, please don't ban me - I'm just doing this to find out what my friends here like, so I can learn Chinese. I'm not selling this data!).
1. Get a list of IDs (I must be friends with them).
I manually maintain Lists of friends I met in each country. I went to my Taiwan list, scrolled down, and copied the source into TextWrangler. A few regex find-replace later, I had a list of all my Taiwanese friends' IDs.
2. Find-replace to make URLs.
My ID is 705630362, so the URL of my Likes page is: https://m.facebook.com/timeline/app_collection/?collection_token=705630362%3A2409997254%3A96 https://m.facebook.com/timeline/app_collection/?collection_t...
3. Scroll down and copy out. This is GUI-intensive, so run it on a spare computer.
tell application "System Events" to tell process "Safari" to key code 119
tell application "Safari" to tell front document to set download_source to do Javascript "document.documentElement.innerHTML;"
Repeat those two while download_source does not contain "<div class=\"_51lb\">". If download_source contains "The page you requested cannot be displayed" then exit repeat.
4. Write it to a file (use cat, not Apple's recommended code, in order to preserve Unicode).
5. Convert to text.
In my case, the HTML files took up 479 MB for 1576 friends. I wrote another script to convert them to text.
Split the HTML based on the "<a class=\"darkTouch _51b5\" href=\"" delimiter.
6. Post-processing!
Now it's time to do research. What are the most common likes? Just combine all the files using cat, and use a bash script to find the most common lines:
cat "input.txt" | sort | uniq -c | sort -n -r > "output.txt"
I plan to write more about this soon, and I'll probably put it on the Pingtype blog. But I might put it on Medium, because people seems to like that these days. Maybe both. There's also my personal website, but I'm worried that people might complain about privacy, so maybe I should distance myself from it. I'm not afraid to write the comment here because we're all hackers.