maybe this will fix it

This commit is contained in:
Juli 2025-03-23 11:08:39 +02:00
parent b3f155a1ca
commit 3c6e1de08c
No known key found for this signature in database

114
main.py
View file

@ -1,89 +1,77 @@
import os
import json
import requests
import image_source ## image source needs to have a `main` function that returns
import requests
import image_source ## image source needs to have a `main` function that returns
# a string which is a link to the source of the image. this function also needs to
# refresh the `out.jpg` to the new image.
baseurl = os.getenv("baseurl")
def post(text,id):
path = "/notes/create"
url = baseurl+path
data = {
# "visibility":"specified",
"text": text,
"mediaIds":[id],
"appSecret": os.getenv("secret")
}
def post(text, id):
path = "/notes/create"
url = baseurl + path
data = {
# "visibility":"specified",
"text": text,
"mediaIds": [id],
"appSecret": os.getenv("secret"),
}
headers = {
"Authorization": f"Bearer {os.getenv('api_key')}",
"Content-Type": "application/json",
}
response = requests.post(url, json=data, headers=headers)
return response
headers = {
'Authorization': f'Bearer {os.getenv("api_key")}',
'Content-Type': 'application/json'
}
def upload_url(fileurl, comment):
path = "/drive/files/upload-from-url"
url = baseurl + path
data = {"url": fileurl, "appSecret": os.getenv("secret"), "comment": comment}
response = requests.post(url, json=data, headers=headers)
return response
headers = {
"Authorization": f"Bearer {os.getenv('api_key')}",
"Content-Type": "application/json",
}
response = requests.post(url, json=data, headers=headers)
return response
def upload_url(fileurl,comment):
path = "/drive/files/upload-from-url"
url = baseurl+path
data = {
"url": fileurl,
"appSecret": os.getenv("secret"),
"comment":comment
}
headers = {
'Authorization': f'Bearer {os.getenv("api_key")}',
'Content-Type': 'application/json'
}
response = requests.post(url, json=data, headers=headers)
return response
def get_id(filename):
path = "/drive/files/find"
url = baseurl+path
path = "/drive/files/find"
url = baseurl + path
data = {
"name":filename,
"appSecret": os.getenv("secret")
}
data = {"name": filename, "appSecret": os.getenv("secret")}
headers = {
"Authorization": f"Bearer {os.getenv('api_key')}",
"Content-Type": "application/json",
}
headers = {
'Authorization': f'Bearer {os.getenv("api_key")}',
'Content-Type': 'application/json'
}
response = requests.post(url, json=data, headers=headers)
json_data = str(response.text)
try:
return json.loads(json_data)[0]["id"]
except IndexError:
return get_id(filename)
response = requests.post(url, json=data, headers=headers)
json_data = str(response.text)
try:
return json.loads(json_data)[0]["id"]
except IndexError:
return get_id(filename)
def main():
posturl, url, artists, characters = image_source.main()
filename = url.split("/")[len(url.split("/"))-1]
upload_url(url, f"SFW yaoi art of the following characters : {characters}")
post(f"Artist(s): {artists}\nSource: {posturl}",get_id(filename))
try:
posturl, url, artists, characters = image_source.main()
filename = url.split("/")[len(url.split("/")) - 1]
upload_url(url, f"SFW yaoi art of the following characters : {characters}")
post(f"Artist(s): {artists}\nSource: {posturl}", get_id(filename))
except:
main()
if __name__ == "__main__":
main()
main()