Path: blob/main/onlyfans_scraper/api/profile.py
1060 views
r"""1_ __2___ _ __ | | _ _ / _| __ _ _ __ ___ ___ ___ _ __ __ _ _ __ ___ _ __3/ _ \ | '_ \ | || | | || |_ / _` || '_ \ / __| _____ / __| / __|| '__| / _` || '_ \ / _ \| '__|4| (_) || | | || || |_| || _|| (_| || | | |\__ \|_____|\__ \| (__ | | | (_| || |_) || __/| |5\___/ |_| |_||_| \__, ||_| \__,_||_| |_||___/ |___/ \___||_| \__,_|| .__/ \___||_|6|___/ |_|7"""89from datetime import datetime10from itertools import zip_longest1112import httpx1314from ..constants import profileEP15from ..utils import auth, dates, encoding161718def scrape_profile(headers, username) -> dict:19with httpx.Client(http2=True, headers=headers) as c:20url = profileEP.format(username)2122auth.add_cookies(c)23c.headers.update(auth.create_sign(url, headers))2425r = c.get(profileEP.format(username), timeout=None)26if not r.is_error:27return r.json()28r.raise_for_status()293031def parse_profile(profile: dict) -> tuple:32media = []33if (avatar := profile['avatar']):34media.append((avatar,))35if (header := profile['header']):36media.append((header,))37# media_urls = list(zip_longest(media, [], fillvalue=None))3839name = encoding.encode_utf_16(profile['name'])40username = profile['username']41id_ = profile['id']42join_date = dates.convert_date_to_mdy(profile['joinDate'])43posts_count = profile['postsCount']44photos_count = profile['photosCount']45videos_count = profile['videosCount']46audios_count = profile['audiosCount']47archived_posts_count = profile['archivedPostsCount']48info = (49name, username, id_, join_date,50posts_count, photos_count, videos_count, audios_count, archived_posts_count)5152return (media, info)535455def print_profile_info(info):56header_fmt = 'Name: {} | Username: {} | ID: {} | Joined: {}\n'57info_fmt = '- {} posts\n -- {} photos\n -- {} videos\n -- {} audios\n- {} archived posts'58final_fmt = header_fmt + info_fmt59print(final_fmt.format(*info))606162def get_id(headers, username):63with httpx.Client(http2=True, headers=headers) as c:64url = profileEP.format(username)6566auth.add_cookies(c)67c.headers.update(auth.create_sign(url, headers))6869r = c.get(url, timeout=None)70if not r.is_error:71return r.json()['id']72r.raise_for_status()737475