Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import requests
- import time
- # set these!
- USERNAME = "" # e621 username
- API_KEY = "" # e621 api key
- # you need to enable API access to get a key.
- # to enable API access, you must go to your e621 API page (Account > Manage API Access) and generate an API key.
- pages = 400
- mode = "aliases" # aliases/implications
- # setting up variables for POST request
- url = "https://e621.net/tag_" + mode + ".json"
- headers = {'user-agent': 'tagAliases/' + USERNAME}
- auth = requests.auth.HTTPBasicAuth(USERNAME, API_KEY)
- # Input the numbers and namespaces that you want to include here
- catMap = {"0":"", "1":"creator:", "3":"series:", "4":"character:", "5":"species:", "8":"lore:"}
- relevantCats = ["0", "1", "3", "4", "5", "8"]
- # 0 General ""
- # 1 Artist "creator:"
- # 3 Copyright "series:"
- # 4 Character "character:"
- # 5 Species "species:"
- # 6 invalid "?"
- # 7 Meta "meta:"
- # 8 Lore "lore:"
- for firstCat in relevantCats:
- for secondCat in relevantCats:
- print('starting ' + firstCat + '-' + secondCat)
- for i in range(1, pages+1, 1):
- r = requests.get(url, params = {"search[antecedent_tag][category]": firstCat, "search[consequent_tag][category]": secondCat, "limit": "1000", "search[order]": "tag_count", "page": i, "search[status]": "Approved"}, headers=headers, auth=auth)
- # stop searches if we get any code back other than 200 (OK)
- if (r.status_code != 200):
- print("ERR:", r.status_code)
- exit
- dummyJsonString = 'tag_' + mode
- dummyJson = {dummyJsonString: []}
- if (r.json() == dummyJson):
- print('finished ' + firstCat + '-' + secondCat + ' at page ' + str(i-1))
- break
- f = open(mode + ".txt", 'a')
- for curTag in r.json():
- if(curTag['consequent_name'] != 'avoid_posting' and curTag['consequent_name'] != 'conditional_dnp'):
- FileLine = catMap[firstCat] + curTag['antecedent_name'] + "\n" + catMap[secondCat] + curTag['consequent_name'] + "\n\n"
- f.write(FileLine)
- # ConsoleLine = catMap[firstCat] + curTag['antecedent_name'] + " -> " + catMap[secondCat] + curTag['consequent_name']
- # print(ConsoleLine)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement