Esempio n. 1
0
def get_account_info_json(username, num_of_posts):
    agent = None
    accountInfo = None
    posts = []
    try:
        accountInfo = AccountInfoEntity(username)
        agent = WebAgent()
        account = WebAgentAccount(username)
        agent.update(account)

        accountInfo.Bio = account.biography
        accountInfo.TotalMediaCount = account.media_count
        posts = agent.get_media(account,
                                count=num_of_posts)[0]  # account.media_count
    except Exception as e:
        print("error while getting account info")

    if agent is None or accountInfo is None:
        return "Coudn't get account Info"

    accountInfo.posts = _get_list_of_parsed_posts(agent, posts)
    accountInfo.parsedPostEntities = posts.count

    accountInfoJson = jsonpickle.encode(accountInfo, unpicklable=False)
    return accountInfoJson
Esempio n. 2
0
    def sortPeoples(self, startSort=0):
        agent = WebAgent()
        if startSort == 0:
            scaningPeoples = self.scaningPeoples
        else:
            scaningPeoples = self.scaningPeoples[startSort:]

        for people in scaningPeoples:
            try:
                account = Account(people)
                agent.update(account)
                biography = account.biography
                name = account.full_name
                infoAcc = biography + name
                print(people)
                if self.sortByTown(infoAcc.lower()) and self.sortByActivity(
                        infoAcc.lower()):
                    self.sortingPeoples.append(people)
                self.currentSortPeople += 1
            except:
                print('errorSort')
                self.offVpn()
                self.onVpn()
                self.playSortPeoples()
        return self.sortingPeoples
Esempio n. 3
0
def get_top_location_posts_json(locationId):
    agent = None
    parsedPosts = []
    try:
        agent = WebAgent()
        location = Location(locationId)
        agent.update(location)
        posts = agent.get_media(location, count=3)[0]
        parsedPosts = _get_list_of_parsed_posts(agent, posts, True)
    except:
        print("error while getting account info")

    top_location_posts_json = jsonpickle.encode(parsedPosts, unpicklable=False)
    return top_location_posts_json
Esempio n. 4
0
def get_top_hashtag_posts_json(hashtag):
    agent = None
    parsedPosts = []
    try:
        agent = WebAgent()
        hashtag = Tag(hashtag)
        agent.update(hashtag)
        posts = agent.get_media(hashtag, count=2)[0]
        parsedPosts = _get_list_of_parsed_posts(agent, posts, True)
    except:
        print("error while getting account info")

    topHashtagPostsJson = jsonpickle.encode(parsedPosts, unpicklable=False)
    return topHashtagPostsJson
Esempio n. 5
0
import os
import time
import random
import argparse
import json

import pandas as pd
from instagram.entities import Media
from instagram.agents import WebAgent
from instagram.exceptions import InternetException
from requests.exceptions import ConnectionError

from datamining.files import DEFAULT_PATH

AG = WebAgent()


def get_post_likes(shortcode: str):
    """
    Collects likes from instagram post by shortcode
    """

    media = Media(shortcode)
    pointer = None
    for i in range(3):
        time.sleep(random.random() * 2)
        try:
            likes, pointer = AG.get_likes(media, pointer)
            # if pointer is None:
            #     return media.likes
        except (ConnectionError, InternetException) as e:
Esempio n. 6
0
def agent():
    return WebAgent()
Esempio n. 7
0
import instagram
from instagram.agents import WebAgent
from instagram import Account, Media, Location
agent = WebAgent()
account = Account("zuck")
loc = Location(17326249)
agent.update(account)
media = agent.get_media(loc, count=50)
print(media)