mirror of https://gitlab.com/bashrc2/epicyon
Command option to test url resolution
parent
b8d294a5da
commit
a09fca3ba0
16
epicyon.py
16
epicyon.py
|
@ -46,6 +46,7 @@ from posts import send_post_via_server
|
|||
from posts import get_public_posts_of_person
|
||||
from posts import get_user_url
|
||||
from posts import check_domains
|
||||
from session import get_resolved_url
|
||||
from session import get_json_valid
|
||||
from session import create_session
|
||||
from session import get_json
|
||||
|
@ -844,6 +845,9 @@ def _command_options() -> None:
|
|||
parser.add_argument('--registration', dest='registration', type=str,
|
||||
default='open',
|
||||
help='Whether new registrations are open or closed')
|
||||
parser.add_argument('--resolve', dest='resolve', type=str,
|
||||
default=None,
|
||||
help='Resolve a shortened url to its full form')
|
||||
parser.add_argument("--nosharedinbox", type=str2bool, nargs='?',
|
||||
const=True, default=False,
|
||||
help='Disable shared inbox')
|
||||
|
@ -892,6 +896,18 @@ def _command_options() -> None:
|
|||
print('All tests succeeded')
|
||||
sys.exit()
|
||||
|
||||
if argb.resolve:
|
||||
proxy_type = None
|
||||
if '.onion/' in argb.resolve:
|
||||
proxy_type = 'tor'
|
||||
elif '.i2p/' in argb.resolve:
|
||||
proxy_type = 'i2p'
|
||||
session = create_session(proxy_type)
|
||||
resolved_url = get_resolved_url(session, argb.resolve)
|
||||
if resolved_url:
|
||||
print('Resolved as: ' + resolved_url)
|
||||
sys.exit()
|
||||
|
||||
http_prefix = 'https'
|
||||
if argb.http or argb.i2p:
|
||||
http_prefix = 'http'
|
||||
|
|
2
maps.py
2
maps.py
|
@ -182,7 +182,7 @@ def _geocoords_from_osmorg_go_link(url: str, session) -> (int, float, float):
|
|||
if '/go/' not in url:
|
||||
return None, None, None
|
||||
|
||||
# TODO resolve url equivalent to
|
||||
# resolve url equivalent to
|
||||
# curl -Ls -o /dev/null -w %{url_effective} [url]
|
||||
resolved_url = get_resolved_url(session, url)
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ def hashtag_rule_tree(operators: [],
|
|||
def _hashtag_add(base_dir: str, http_prefix: str, domain_full: str,
|
||||
post_json_object: {},
|
||||
action_str: str, hashtags: [], system_language: str,
|
||||
translate: {}) -> None:
|
||||
translate: {}, session) -> None:
|
||||
"""Adds a hashtag via a hashtag rule
|
||||
"""
|
||||
add_hashtag = action_str.split('add ', 1)[1].strip()
|
||||
|
@ -386,7 +386,7 @@ def _newswire_hashtag_processing(base_dir: str, post_json_object: {},
|
|||
domain: str, port: int,
|
||||
moderated: bool, url: str,
|
||||
system_language: str,
|
||||
translate: {}) -> bool:
|
||||
translate: {}, session) -> bool:
|
||||
"""Applies hashtag rules to a news post.
|
||||
Returns true if the post should be saved to the news timeline
|
||||
of this instance
|
||||
|
@ -436,7 +436,7 @@ def _newswire_hashtag_processing(base_dir: str, post_json_object: {},
|
|||
# add a hashtag
|
||||
_hashtag_add(base_dir, http_prefix, domain_full,
|
||||
post_json_object, action_str, hashtags,
|
||||
system_language, translate)
|
||||
system_language, translate, session)
|
||||
elif action_str.startswith('remove '):
|
||||
# remove a hashtag
|
||||
_hashtag_remove(http_prefix, domain_full, post_json_object,
|
||||
|
@ -720,7 +720,7 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str,
|
|||
_newswire_hashtag_processing(base_dir, blog, hashtags,
|
||||
http_prefix, domain, port,
|
||||
moderated, url, system_language,
|
||||
translate)
|
||||
translate, session)
|
||||
|
||||
# save the post and update the index
|
||||
if save_post:
|
||||
|
|
|
@ -114,12 +114,12 @@ def get_resolved_url(session, url: str, timeout_sec: int = 20) -> {}:
|
|||
if '://' in result.url:
|
||||
return result.url
|
||||
except ValueError as exc:
|
||||
print('EX: _get_resolved_url failed, url: ' +
|
||||
print('EX: get_resolved_url failed, url: ' +
|
||||
str(url) + ', ' + str(exc))
|
||||
except SocketError as exc:
|
||||
if exc.errno == errno.ECONNRESET:
|
||||
print('EX: _get_resolved_url failed, ' +
|
||||
'connection was reset during _get_resolved_url ' + str(exc))
|
||||
print('EX: get_resolved_url failed, ' +
|
||||
'connection was reset ' + str(exc))
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue