forked from upbit/pixivpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_tag_translations.py
37 lines (26 loc) · 1 KB
/
example_tag_translations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import *
from pixivpy3 import *
import sys
if sys.version_info >= (3, 0):
import imp
imp.reload(sys)
else:
reload(sys)
sys.setdefaultencoding('utf8')
sys.dont_write_bytecode = True
# get your refresh_token, and replace _REFRESH_TOKEN
# https://github.com/upbit/pixivpy/issues/158#issuecomment-778919084
_REFRESH_TOKEN = "0zeYA-PllRYp1tfrsq_w3vHGU1rPy237JMf5oDt73c4"
def main():
aapi = AppPixivAPI()
# aapi.set_additional_headers({'Accept-Language':'en-US'})
aapi.set_accept_language('en-us') # zh-cn
aapi.auth(refresh_token=_REFRESH_TOKEN)
json_result = aapi.illust_ranking('day', date=(datetime.now() - timedelta(days=5)).strftime('%Y-%m-%d'))
print("Printing image titles and tags with English tag translations present when available")
for illust in json_result.illusts[:3]:
print("Illustration: \"" + str(illust.title) + "\"\nTags: " + str(illust.tags) + "\n")
if __name__ == '__main__':
main()