1
0
Fork 0

Support for cohost
Python Package / Package (push) Has been skipped Details

This commit is contained in:
Jon Michael Aanes 2023-12-16 23:09:27 +01:00
parent 95a446dbd1
commit 55989ec085
3 changed files with 38 additions and 29 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
__pycache__/
/build/
/dist/
dist
*.egg-info

View File

@ -55,6 +55,7 @@ class SocialSiteId(enum.Enum):
BLUESKY_PROFILE = 32
ITCH_IO_DEVELOPER = 8176
FIREFOX_PROFILE_BOOKMARKS = 33
COHOST_PROFILE = 117203288
def wikidata_property(self, client):
return client.get(WIKIDATA_PROPERTIES[self])
@ -123,6 +124,7 @@ WIKIDATA_PROPERTIES = {
SocialSiteId.BANDCAMP_PROFILE: WikidataInfo(3283, 545966),
SocialSiteId.BLUESKY_PROFILE: WikidataInfo(None, 78194383),
SocialSiteId.ITCH_IO_DEVELOPER: WikidataInfo(8176, 22905933),
SocialSiteId.COHOST_PROFILE: WikidataInfo(None, 117203288),
}
def re_social_subdomain(main_domain):
@ -190,6 +192,7 @@ URL_PARSE_DANBOORU_ARTIST = re_social_path_adv('danbooru.donmai.us', 'artists',
URL_PARSE_BANDCAMP = re_social_subdomain('bandcamp.com')
URL_PARSE_BLUESKY = re_social_path_adv('bsky.app', 'profile', RE_ID)
URL_PARSE_ITCH_IO_DEVELOPER = re_social_subdomain('itch.io')
URL_PARSE_COHOST = re_social_path_adv('cohost.org', RE_ID)
REGEXES = [
# Reddit
@ -290,6 +293,9 @@ REGEXES = [
# Itch.io
(URL_PARSE_ITCH_IO_DEVELOPER, SocialSiteId.ITCH_IO_DEVELOPER),
# Cohost
(URL_PARSE_COHOST, SocialSiteId.COHOST_PROFILE),
]
WELL_KNOWN_MASTODON_INSTANCES = frozenset({
@ -345,32 +351,3 @@ def determine_social_from_url(url):
return None
return SocialLink(url, social_site_id, social_id)
def run_tests():
assert determine_social_from_url('http://www.twitter.com/dril').social_id == 'dril'
assert determine_social_from_url('http://worstdril.tumblr.com/')
assert determine_social_from_url('https://deep-dark-fears.tumblr.com').social_id == 'deep-dark-fears'
assert determine_social_from_url('https://www.etsy.com/shop/aleksiremesart').social_id == 'aleksiremesart'
assert determine_social_from_url('https://ko-fi.com/A627LI1/shop').social_id == 'A627LI1'
assert determine_social_from_url('https://ko-fi.com/A627LI1/').social_id == 'A627LI1'
assert determine_social_from_url('https://www.facebook.com/fredagscafeen.dk/').social_id == 'fredagscafeen.dk'
assert determine_social_from_url('https://www.tiktok.com/@depthsofwikipedia?lang=en').social_id == 'depthsofwikipedia'
assert determine_social_from_url('https://www.pixiv.net/users/14866303').social_id == '14866303'
assert determine_social_from_url('https://www.pixiv.net/member.php?id=109710').social_id == '109710'
assert determine_social_from_url('https://www.deviantart.com/solquiet').social_site_id == SocialSiteId.DEVIANT_ART_ACCOUNT
assert determine_social_from_url('https://solquiet.deviantart.com/').social_site_id == SocialSiteId.DEVIANT_ART_ACCOUNT
INSTAGRAMS = [
'https://instagram.com/_richardparry_',
'https://instagram.com/j_kmor/',
'https://instagram.com/cullensartbox/',
'https://www.instagram.com/timkongart/',
'https://www.instagram.com/kcn.wu/',
'https://www.instagram.com/itsbettyjiang',
]
for ig in INSTAGRAMS:
assert determine_social_from_url(ig).social_site_id == SocialSiteId.INSTAGRAM_PAGE
TEST = True
if TEST:
run_tests()

30
test/test_parsing.py Normal file
View File

@ -0,0 +1,30 @@
from socials_util import *
def test_parsing():
assert determine_social_from_url('http://www.twitter.com/dril').social_id == 'dril'
assert determine_social_from_url('http://worstdril.tumblr.com/')
assert determine_social_from_url('https://deep-dark-fears.tumblr.com').social_id == 'deep-dark-fears'
assert determine_social_from_url('https://www.etsy.com/shop/aleksiremesart').social_id == 'aleksiremesart'
assert determine_social_from_url('https://ko-fi.com/A627LI1/shop').social_id == 'A627LI1'
assert determine_social_from_url('https://ko-fi.com/A627LI1/').social_id == 'A627LI1'
assert determine_social_from_url('https://www.facebook.com/fredagscafeen.dk/').social_id == 'fredagscafeen.dk'
assert determine_social_from_url('https://www.tiktok.com/@depthsofwikipedia?lang=en').social_id == 'depthsofwikipedia'
assert determine_social_from_url('https://www.pixiv.net/users/14866303').social_id == '14866303'
assert determine_social_from_url('https://www.pixiv.net/member.php?id=109710').social_id == '109710'
assert determine_social_from_url('https://www.deviantart.com/solquiet').social_site_id == SocialSiteId.DEVIANT_ART_ACCOUNT
assert determine_social_from_url('https://solquiet.deviantart.com/').social_site_id == SocialSiteId.DEVIANT_ART_ACCOUNT
assert determine_social_from_url('https://cohost.org/example').social_site_id == SocialSiteId.COHOST_PROFILE
INSTAGRAMS = [
'https://instagram.com/_richardparry_',
'https://instagram.com/j_kmor/',
'https://instagram.com/cullensartbox/',
'https://www.instagram.com/timkongart/',
'https://www.instagram.com/kcn.wu/',
'https://www.instagram.com/itsbettyjiang',
]
for ig in INSTAGRAMS:
assert determine_social_from_url(ig).social_site_id == SocialSiteId.INSTAGRAM_PAGE