def test_update(): anon = Agent() anon.update() assert (not getattr(anon, "_rhx_gis", None) is None) assert (not getattr(anon, "_csrf_token", None) is None)
def profile_exists(username): try: agent = Agent() account = Account(username) agent.update(account) return True except: return False
def get_posts_by_tag_name(tagname, num=None, path=None): agent = Agent() agent.update(Tag(tagname)) tag = Tag(tagname) media = set() pointer = None if num == None: media_count = tag.media_count else: media_count = num limit = 50 batch_num = math.ceil(media_count / limit) for i in range(batch_num): if i == batch_num - 1: count = media_count - limit * (batch_num - 1) batch_media, pointer = agent.get_media(tag, pointer=pointer, count=count) else: batch_media, pointer = agent.get_media(tag, pointer=pointer, count=limit) for j, item in enumerate(batch_media): print("Getting media: " + str(i * 50 + j + 1) + " / " + str(media_count)) agent.update(Media(item.code)) media.add(Media(item.code)) media_posts = {} for i, item in enumerate(media): post_info = copy.copy(item) post_info.likes = dict(post_info.likes) post_info.comments = dict(post_info.comments) post_info.location = str(post_info.location) media_posts[i] = post_info.__dict__ media_dict = {"posts": media_posts} media_json = json.dumps(media_dict, indent=2) print(media_json) if path == None: path = './data/tag__' + tagname pathlib.Path(path).mkdir(parents=True, exist_ok=True) filename = path + '/tag__' + tagname + '__last_posts.json' with open(filename, 'w', newline='', encoding='utf8') as f: f.write(media_json) return media
def test_get_media_account_long(count, username): anon = Agent() account = Account(username) anon.update(account) count = account.media_count data, pointer = anon.get_media(account, count=count) assert (min(account.media_count, count) == len(data)) assert ((pointer is None) == (account.media_count <= count)) Account.clear_cache() Media.clear_cache()
def test_update_tag(name): anon = Agent() tag = Tag(name) data = anon.update(tag) Tag.clear_cache()
def test_update_location(id): anon = Agent() location = Location(id) data = anon.update(location) Location.clear_cache()
def test_update_video(shortcode): anon = Agent() video = Media(shortcode) data = anon.update(video) assert (video.is_video) Media.clear_cache()
def test_update_photo_set(shortcode): anon = Agent() photo_set = Media(shortcode) data = anon.update(photo_set) assert (not photo_set.is_video) Media.clear_cache()
def get_tag_info(tagname, path=None): agent = Agent() agent.update(Tag(tagname)) tag = Tag(tagname) tag_info = copy.copy(tag) tag_info.media = dict(tag_info.media) tag_dict = {"tag": tag_info.__dict__} tag_json = json.dumps(tag_dict, indent=2) if path == None: path = './data/tag__' + tagname pathlib.Path(path).mkdir(parents=True, exist_ok=True) filename = path + '/tag__' + tagname + '__tag_info.json' with open(filename, 'w', newline='', encoding='utf8') as f: f.write(tag_json) return tag
def get_account_info(username, path=None): agent = Agent() agent.update(Account(username)) account = Account(username) account_info = copy.copy(account) account_info.media = dict(account_info.media) account_info.follows = dict(account_info.follows) account_info.followers = dict(account_info.followers) account_dict = {"account": account_info.__dict__} account_json = json.dumps(account_dict, indent=2) if path == None: path = './data/' + username pathlib.Path(path).mkdir(parents=True, exist_ok=True) filename = path + '/' + username + '__account_info.json' with open(filename, 'w', newline='', encoding='utf8') as f: f.write(account_json) return account
def test_update_account(username): anon = Agent() account = Account(username) data = anon.update(account) assert (not data is None) assert (not account.id is None) assert (not account.full_name is None) assert (not account.profile_pic_url is None) assert (not account.profile_pic_url_hd is None) assert (not account.biography is None) assert (not account.follows_count is None) assert (not account.followers_count is None) assert (not account.media_count is None) assert (not account.is_private is None) assert (not account.is_verified is None) assert (not account.country_block is None) Account.clear_cache()
def is_profile_private(username): agent = Agent() account = Account(username) agent.update(account) return account.is_private