all repos — sunstroke @ dc852443b5738a07c869b612ca3ed6db9d3c3777

add custom resolver, bugfix
Andronaco Marco marco.andronaco@olivetti.com
Thu, 13 Jul 2023 11:27:07 +0200
commit

dc852443b5738a07c869b612ca3ed6db9d3c3777

parent

19ce085fa872db7f4f15e230524889ac5322f8a5

3 files changed, 18 insertions(+), 12 deletions(-)

jump to
M MyResolver.pyMyResolver.py

@@ -5,7 +5,7 @@ def resolve(self, hostname):

import random ips = [ '104.16.89.20', # CloudFlare - '151.101.2.109', # Fastly + #'151.101.2.109', # Fastly ] resolutions = { 'overpost.biz': random.choice(ips),
M Overpost.pyOverpost.py

@@ -3,9 +3,7 @@ from datetime import datetime

from re import compile import os import feedparser -from dotenv import load_dotenv from MyResolver import get -load_dotenv() RSS_URL = os.getenv("RSS_URL") or os.path.join(".", "rss.xml") N_LINKS_TO_REMOVE = os.getenv("N_LINKS_TO_REMOVE") or 2

@@ -67,7 +65,7 @@ return (datetime.strptime(date, "%d.%m.%Y"), links)

def handle_url(url): if url.startswith("http"): - return get(url) + return get(url).text else: return url
M main.pymain.py

@@ -1,8 +1,11 @@

+ +from urllib.error import URLError +from datetime import datetime +from os import getenv +from dotenv import load_dotenv +load_dotenv() from Overpost import get_newspaper from MyPyload import Pyload -from urllib.error import URLError -from os import getenv -from datetime import datetime NEWSPAPER_PREFIX = getenv("NEWSPAPER_PREFIX") or "" HOST_PREFERENCE = [ 'katfile.com', 'rapidgator.net', 'www.easybytez.com' ]

@@ -19,14 +22,18 @@

def get_host(link): return link.split("/")[2] -def filter_links(links, host): +def filter_links(links, hosts): + host = next(hosts) for link in links: + print(link, host) if get_host(link) == host: return link + return filter_links(links, hosts) + def get_sorted_links(dictionary): hosts = scroll_list(HOST_PREFERENCE) - return [ filter_links(links, next(hosts)) for _, links in dictionary.items() ] + return [ filter_links(links, hosts) for _, links in dictionary.items() ] def download_link(connection, name, link): return connection.addPackage(name=name, links=[link])

@@ -38,9 +45,10 @@ return [ download_link(con, name, link) for link in links ]

except URLError: print("\nConnessione a Pyload rifiutata.") - print("Link da aggiungere manualmente:\n") - print("\n".join(links)) - print("") + print(len(links), "link da aggiungere manualmente:\n") + for link in links: + print(link) + print() return [] def main():