Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import requests
- import sys
- import time
- def get_nightcafe_user_feed (user_id, json_file=None, image_path=None, max_items=999999999):
- base_url = "https://api.nightcafe.studio/creations?query=user-recent&user="
- last_id = None
- items = []
- going = True
- while going:
- url = base_url + user_id
- if last_id:
- url = url + "&lastVisibleId=" + last_id
- r = requests.get (url)
- data = r.json ()
- last_id = data["lastVisibleId"]
- going = last_id != ""
- results = data["results"]
- items.extend (results)
- if len (items) >= max_items:
- going = False
- time.sleep (1)
- if json_file is not None:
- with open (json_file, "w") as f:
- json.dump (items, f, indent=2)
- if image_path is not None:
- image_path = image_path.strip ()
- if not image_path.endswith ("/"):
- image_path = image_path + "/"
- for item in items:
- url = "https://images.nightcafe.studio/" + item["output"]
- image = requests.get (url).content
- with open (image_path + item["id"] + ".jpeg", "wb") as f:
- f.write (image)
- return items
- def get_nightcafe_followers (user_id, json_file=None, max_items=999999999):
- base_url = "https://api.nightcafe.studio/follows?query=user-followers&user="
- last_id = None
- items = []
- going = True
- while going:
- url = base_url + user_id
- if last_id:
- url = url + "&lastVisibleId=" + last_id
- r = requests.get (url)
- data = r.json ()
- last_id = data["lastVisibleId"]
- going = last_id != ""
- results = data["results"]
- items.extend (results)
- if len (items) >= max_items:
- going = False
- time.sleep (1)
- if json_file is not None:
- with open (json_file, "w") as f:
- json.dump (items, f, indent=2)
- return items
- if __name__ == "__main__":
- user_id = sys.argv[1]
- get_nightcafe_user_feed (user_id, json_file=user_id + "_nightcafe_feed.json"),
- get_nightcafe_followers (user_id, json_file=user_id + "_nightcafe_followers.json")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement