From cf3676f461fe9e6338c3079446306a0e97355ca9 Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Tue, 21 Apr 2020 16:17:10 +0930 Subject: [PATCH] Add scraper example --- FaveScraper.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 FaveScraper.py diff --git a/FaveScraper.py b/FaveScraper.py new file mode 100755 index 0000000..5f48a6e --- /dev/null +++ b/FaveScraper.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 + +import multiprocessing + +import requests + +from FAAPI import FAAPI + + +def download(url: str): + print('Downloading ' + url) + with open(url.split('/')[-1], 'wb') as file: + res = requests.get(url) + file.write(res.content) + + +if __name__ == '__main__': + # Get an API instance + api = FAAPI() + + # Get the user we've authenticated as + user = api.get_user(api.username) + if not user: + print('Failed to get user') + exit(1) + + # Get the download URLs from each fave + download_urls = [] + for fave in user.faves[0:50]: + print('Scraping ' + str(fave.id)) + download_urls.append(fave.download_url) + + # Download them all + pool = multiprocessing.Pool(processes=10) + pool.map(download, download_urls)