Use facebook scraper
Facebook graph API was too annoying to use so I switched to using a good old scraper
This commit is contained in:
parent
943f55b084
commit
92863bd82c
3 changed files with 38 additions and 8 deletions
|
@ -31,8 +31,8 @@
|
|||
# Update the menu every day
|
||||
0 0 * * * cd "$HOME"/public_html/v2/menu/ && ./menu_update.sh >/dev/null 2>&1
|
||||
|
||||
# Update facebook data every minute
|
||||
* * * * * cd "$HOME"/public_html/v2/facebook/ && ./facebook_update.sh >/dev/null 2>&1
|
||||
# Update facebook data every 5 minute
|
||||
5 * * * * cd "$HOME"/public_html/v2/facebook/ && ./facebook_update.sh >/dev/null 2>&1
|
||||
|
||||
# Update the dashboard every 20 sec. The dashboard also update the machine list
|
||||
# Call 3 times, one with a 20 sec delay, and one with 40 sec, because cron cannot call more than each minute
|
||||
|
|
35
facebook/facebook_handler.py
Normal file
35
facebook/facebook_handler.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import json
|
||||
from facebook_scraper import get_posts
|
||||
|
||||
FILE = 'facebook_data.json'
|
||||
|
||||
|
||||
def scrape_data():
|
||||
post_list = []
|
||||
for post in get_posts('amicale.deseleves', pages=3):
|
||||
print(post)
|
||||
cleaned_post = {
|
||||
"post_id": post["post_id"],
|
||||
"post_text": post["post_text"],
|
||||
"post_url": post["post_url"],
|
||||
"image": post["image"],
|
||||
"video": post["video"],
|
||||
"link": post["link"],
|
||||
"time": post["time"].timestamp(),
|
||||
}
|
||||
post_list.append(cleaned_post)
|
||||
return post_list
|
||||
|
||||
|
||||
def write_data(data):
|
||||
with open(FILE, 'w') as f:
|
||||
json.dump(data, f)
|
||||
|
||||
|
||||
def main():
|
||||
print("Fetching facebook data...")
|
||||
write_data(scrape_data())
|
||||
print('DONE')
|
||||
|
||||
|
||||
main()
|
|
@ -1,10 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
# A token is required to access the facebook public page
|
||||
# This token must be saved in a file named "token" in the same folder as this script
|
||||
# /!\ Do not sync this token with git /!\
|
||||
|
||||
touch lock
|
||||
token=$(cat token)
|
||||
curl "https://graph.facebook.com/v7.0/amicale.deseleves/published_posts?fields=full_picture,message,permalink_url,created_time&date_format=U&access_token=$token" > facebook_data.json
|
||||
python3 facebook_handler.py > log 2> err
|
||||
rm lock
|
||||
|
|
Loading…
Reference in a new issue