added loop functionality and removed debug lines
This commit is contained in:
parent
7ec10f4d6d
commit
0437f76af3
33
lolibot.py
33
lolibot.py
|
@ -3,7 +3,7 @@ from generate_config import generate_config
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import time
|
||||||
parent = os.path.dirname(os.path.realpath(__file__))
|
parent = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
if not os.path.exists(os.path.join(parent, 'config.json')):
|
if not os.path.exists(os.path.join(parent, 'config.json')):
|
||||||
|
@ -14,16 +14,21 @@ with open(os.path.join(parent, 'config.json'), 'r') as config_file:
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.headers.update({"Authorization" : "Bearer " + config['user_token']})
|
session.headers.update({"Authorization" : "Bearer " + config['user_token']})
|
||||||
|
|
||||||
post = requests.get('https://gelbooru.com/index.php', params={'page':'dapi','s':'post', 'q':'index', 'limit':1, 'tags':'loli sort:random score:>=10', 'json':1}).json()['post'][0]
|
def make_post():
|
||||||
print(post['id'])
|
post = requests.get('https://gelbooru.com/index.php', params={'page':'dapi','s':'post', 'q':'index', 'limit':1, 'tags':'loli sort:random score:>=10', 'json':1}).json()['post'][0]
|
||||||
with tempfile.TemporaryFile('w+b', suffix='.' + post['file_url'].split('.')[-1]) as image:
|
print(post['id'])
|
||||||
#with open('image.' + post['file_url'].split('.')[-1], 'w+b') as image:
|
with tempfile.TemporaryFile('w+b', suffix='.' + post['file_url'].split('.')[-1]) as image:
|
||||||
image.write(requests.get(post['file_url']).content)
|
#with open('image.' + post['file_url'].split('.')[-1], 'w+b') as image:
|
||||||
image.seek(0)
|
image.write(requests.get(post['file_url']).content)
|
||||||
attachment = session.post(config['instance'] + '/api/v2/media', files={'file':image}, data={'description': 'gelbooru ID: ' + str(post['id'])}).json()
|
image.seek(0)
|
||||||
print(attachment)
|
attachment = session.post(config['instance'] + '/api/v2/media', files={'file':image}, data={'description': 'gelbooru ID: ' + str(post['id'])}).json()
|
||||||
content = 'source: https://gelbooru.com/index.php?page=post&s=view&id=' + str(post['id'])
|
content = 'source: https://gelbooru.com/index.php?page=post&s=view&id=' + str(post['id'])
|
||||||
if not 'source_request' in post['tags'].split(' '):
|
if not 'source_request' in post['tags'].split(' '):
|
||||||
content = 'source: ' + post['source']
|
content = 'source: ' + post['source']
|
||||||
sensitive = True
|
sensitive = True
|
||||||
print(session.post(config['instance'] + '/api/v1/statuses', json={'status':content, 'media_ids':[attachment['id']], 'visibility':'direct', 'sensitive': True}).json())
|
session.post(config['instance'] + '/api/v1/statuses', json={'status':content, 'media_ids':[attachment['id']], 'visibility':'unlisted', 'sensitive': True})
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
make_post()
|
||||||
|
time.sleep(1 * 60 * 60)
|
Loading…
Reference in New Issue