zip support for some archival software
This commit is contained in:
parent
a6bea077bc
commit
76529a1264
31
twitfix.py
31
twitfix.py
@ -16,6 +16,7 @@ from cache import addVnfToLinkCache,getVnfFromLinkCache
|
||||
from yt_dlp.utils import ExtractorError
|
||||
from twitter.api import TwitterHTTPError
|
||||
import vxlogging as log
|
||||
import zipfile
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
@ -94,6 +95,30 @@ def twitfix(sub_path):
|
||||
return abort(500,"Failed to scan tweet: "+e)
|
||||
return abort(500,"Failed to scan tweet")
|
||||
return make_content_type_response(getTemplate("txt.html",vnf,vnf["description"],"",clean,"","","",""),"text/plain")
|
||||
elif request.url.endswith(".zip") or request.url.endswith("%2Ezip"): # for certain types of archival software (i.e Hydrus)
|
||||
twitter_url = "https://twitter.com/" + sub_path
|
||||
|
||||
if "?" not in request.url:
|
||||
clean = twitter_url[:-4]
|
||||
else:
|
||||
clean = twitter_url
|
||||
|
||||
vnf,e = vnfFromCacheOrDL(clean)
|
||||
if vnf is None:
|
||||
if e is not None:
|
||||
return abort(500,"Failed to scan tweet: "+e)
|
||||
return abort(500,"Failed to scan tweet")
|
||||
with app.app_context():
|
||||
txtData = getTemplate("txt.html",vnf,vnf["description"],"",clean,"","","","")
|
||||
txtIo = BytesIO()
|
||||
txtIo.write(txtData.encode("utf-8"))
|
||||
txtIo.seek(0)
|
||||
zipIo = BytesIO()
|
||||
with zipfile.ZipFile(zipIo, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
zipf.writestr("tweetInfo.txt", txtIo.read())
|
||||
# todo: add images to zip
|
||||
zipIo.seek(0)
|
||||
return make_content_type_response(zipIo,"application/zip")
|
||||
elif request.url.startswith("https://d.vx"): # Matches d.fx? Try to give the user a direct link
|
||||
if isValidUserAgent(user_agent):
|
||||
twitter_url = config['config']['url'] + "/"+sub_path
|
||||
@ -172,11 +197,17 @@ def twitfix(sub_path):
|
||||
hashtags.append(i["text"])
|
||||
|
||||
include_txt = request.args.get("include_txt", "false")
|
||||
include_zip = request.args.get("include_zip", "false") # for certain types of archival software (i.e Hydrus)
|
||||
|
||||
if include_txt == "true" or (include_txt == "ifnomedia" and len(media)==0):
|
||||
txturl = config['config']['url']+"/"+userL["screen_name"]+"/status/"+tweet["rest_id"]+".txt"
|
||||
media.append(txturl)
|
||||
media_extended.append({"url":txturl,"type":"txt"})
|
||||
if include_zip == "true" or (include_zip == "ifnomedia" and len(media)==0):
|
||||
zipurl = config['config']['url']+"/"+userL["screen_name"]+"/status/"+tweet["rest_id"]+".zip"
|
||||
media.append(zipurl)
|
||||
media_extended.append({"url":zipurl,"type":"zip"})
|
||||
|
||||
apiObject = {
|
||||
"text": tweetL["full_text"],
|
||||
"likes": tweetL["favorite_count"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user