generalized output of fetch

This commit is contained in:
likhy 2023-08-29 23:56:49 -07:00
parent 26b7d47996
commit 9fbdf2a8a7

View File

@ -374,6 +374,8 @@ if __name__ == "__main__":
print(json.dumps(profile), file=f) print(json.dumps(profile), file=f)
def fn1(webring_config): # come up with better name later/ def fn1(webring_config): # come up with better name later/
import pycurl
from io import BytesIO
def get_proxy(): def get_proxy():
proxy = "" proxy = ""
if "http_proxy" in os.environ: if "http_proxy" in os.environ:
@ -385,9 +387,7 @@ if __name__ == "__main__":
foo = proxy.find("socks://") >= 0 or proxy.find("socks5h://") foo = proxy.find("socks://") >= 0 or proxy.find("socks5h://")
return host, int(port), foo return host, int(port), foo
def fetch(follow_list): def fetch(url_list):
import pycurl
from io import BytesIO
curl = pycurl.Curl() curl = pycurl.Curl()
if "http_proxy" in os.environ or "https_proxy" in os.environ: if "http_proxy" in os.environ or "https_proxy" in os.environ:
hostname, port_no, is_socks = get_proxy() hostname, port_no, is_socks = get_proxy()
@ -395,28 +395,34 @@ if __name__ == "__main__":
curl.setopt(pycurl.PROXYPORT, port_no) curl.setopt(pycurl.PROXYPORT, port_no)
if is_socks: if is_socks:
curl.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME) curl.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
other_people = [] datum = []
for someone in follow_list: for url in url_list:
buf = BytesIO() buf = BytesIO()
curl.setopt(curl.WRITEDATA, buf) curl.setopt(curl.WRITEDATA, buf)
curl.setopt(pycurl.URL, someone) curl.setopt(pycurl.URL, url)
try: try:
curl.perform() curl.perform()
other_people.append(json.loads(buf.getvalue())) datum.append(buf)
except pycurl.error as e: except pycurl.error as e:
print(e,": ", someone, file=sys.stderr) print(e,": ", url, file=sys.stderr)
# print(buf.getvalue(),"\n\t", curl.getinfo(curl.CONTENT_TYPE), file=sys.stderr) # print(buf.getvalue(),"\n\t", curl.getinfo(curl.CONTENT_TYPE), file=sys.stderr)
curl.close() curl.close()
return other_people return datum
list_of_json_objs = fetch(webring_config["list"]) def to_json(curl_outs):
try: json_objs = []
list_of_json_objs.sort(key=lambda e: e["last-updated"], reverse=True) for buf in curl_outs:
except: try:
pass json_objs.append(json.loads(buf.getvalue()))
except Exception as e:
print(e)
return json_objs
list_of_json_objs = to_json(fetch(webring_config["list"]))
if list_of_json_objs == []: if list_of_json_objs == []:
print("no remote profiles loaded", file=sys.stderr) print("no remote profiles loaded", file=sys.stderr)
return [] return []
list_of_json_objs.sort(key=lambda e: e["last-updated"], reverse=True)
rendered = [] rendered = []
template = webring_config["format"] template = webring_config["format"]
SHORT_BIO_LIMIT = 150 SHORT_BIO_LIMIT = 150