Advertisement
Guest User

Get E621 Species Siblings

a guest
Sep 30th, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import requests
  4. import time
  5.  
  6. # set these!
  7. USERNAME = "" # e621 username
  8. API_KEY = "" # e621 api key
  9. # you need to enable API access to get a key.
  10. # to enable API access, you must go to your e621 API page (Account > Manage API Access) and generate an API key.
  11.  
  12. pages = 400
  13.  
  14.  
  15.  
  16.  
  17. # setting up variables for POST request
  18. url = "https://e621.net/tags.json"
  19. headers = {'user-agent': 'tagSpecies/' + USERNAME}
  20. auth = requests.auth.HTTPBasicAuth(USERNAME, API_KEY)
  21.  
  22. for i in range(1, pages+1, 1):
  23.     r = requests.get(url, params = {"search[category]": "5", "limit": "1000", "search[order]": "count", "page": i}, headers=headers, auth=auth)
  24.  
  25.     # stop searches if we get any code back other than 200 (OK)
  26.     if (r.status_code != 200):
  27.         print("ERR:", r.status_code)
  28.         exit
  29.  
  30.     f = open("species.txt", 'a')
  31.     for curTag in r.json():
  32.         FileLine = curTag['name'] + "\n" + "species:" + curTag['name'] + "\n\n"
  33.         f.write(FileLine)
  34.         ConsoleLine = curTag['name'] + " -> " + "species:" + curTag['name']
  35.         print(ConsoleLine)
  36.  
  37.     f.close()
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement