예제 #1
0
def get_dp(username: str) -> str:
    """
    Funtion to get dp url of the username
    """
    try:
        user = InstagramUser(username)
        return user.profile_picture_url
    except (KeyError, TypeError, IndexError):
        print("username not found")
        sys.exit(1)
예제 #2
0
def Search(Query_List, Task_ID, Type, Limit=10):

    try:
        Data_to_Cache = []
        Directory = General.Make_Directory(Plugin_Name.lower())
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        Log_File = General.Logging(Directory, Plugin_Name.lower())
        handler = logging.FileHandler(os.path.join(Directory, Log_File), "w")
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter("%(levelname)s - %(message)s")
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        Cached_Data_Object = General.Cache(Directory, Plugin_Name)
        Cached_Data = Cached_Data_Object.Get_Cache()
        Query_List = General.Convert_to_List(Query_List)
        Limit = General.Get_Limit(Limit)

        for Query in Query_List:

            if Type == "User":
                from instagramy import InstagramUser
                Local_Plugin_Name = Plugin_Name + "-" + Type
                CSE_Response = InstagramUser(Query)
                JSON_Object = Common.JSON_Handler(vars(CSE_Response))
                CSE_JSON_Output_Response = JSON_Object.Dump_JSON()
                Main_File = General.Main_File_Create(
                    Directory, Local_Plugin_Name, CSE_JSON_Output_Response,
                    Query, The_File_Extensions["Main"])

                if not CSE_Response.is_private:
                    Posts = CSE_Response.posts
                    Output_Connections = General.Connections(
                        Query, Local_Plugin_Name, Domain,
                        "Social Media - Person", Task_ID,
                        Local_Plugin_Name.lower())
                    Current_Step = 0

                    for Post in Posts:
                        URL = Post['post_url']
                        Shortcode = URL.replace(f"https://www.{Domain}/p/",
                                                "").replace("/", "")
                        Title = "IG | " + General.Get_Title(URL, Requests=True)

                        if URL not in Cached_Data and URL not in Data_to_Cache and Current_Step < int(
                                Limit):
                            Responses = Common.Request_Handler(
                                URL,
                                Application_JSON_CT=True,
                                Accept_XML=True,
                                Accept_Language_EN_US=True,
                                Filter=True,
                                Host=f"https://www.{Domain}")
                            Response = Responses["Filtered"]
                            Output_file = General.Create_Query_Results_Output_File(
                                Directory, Query, Local_Plugin_Name, Response,
                                Shortcode, The_File_Extensions["Query"])

                            if Output_file:
                                Output_Connections.Output(
                                    [Main_File, Output_file], URL, Title,
                                    Plugin_Name.lower())
                                Data_to_Cache.append(URL)

                            else:
                                logging.warning(
                                    f"{Common.Date()} - {__name__.strip('plugins.')} - Failed to create output file. File may already exist."
                                )

                            Current_Step += 1

                else:
                    logging.info(
                        f"{Common.Date()} - {__name__.strip('plugins.')} - The provided user's profile is private and cannot be scraped."
                    )

            elif Type == "Tag":
                from instagramy import InstagramHashTag
                Local_Plugin_Name = Plugin_Name + "-" + Type
                CSE_Response = InstagramHashTag(Query)
                JSON_Object = Common.JSON_Handler(vars(CSE_Response))
                CSE_JSON_Output_Response = JSON_Object.Dump_JSON()
                Main_File = General.Main_File_Create(
                    Directory, Local_Plugin_Name, CSE_JSON_Output_Response,
                    Query, The_File_Extensions["Main"])
                Posts = vars(
                    CSE_Response)['tag_data']['edge_hashtag_to_media']['edges']
                Output_Connections = General.Connections(
                    Query, Local_Plugin_Name, Domain, "Social Media - Person",
                    Task_ID, Local_Plugin_Name.lower())
                Current_Step = 0

                for Post in Posts:
                    Shortcode = Post['node']['shortcode']
                    URL = f"https://www.{Domain}/p/{Shortcode}/"
                    Title = "IG | " + General.Get_Title(URL, Requests=True)

                    if URL not in Cached_Data and URL not in Data_to_Cache and Current_Step < int(
                            Limit):
                        Responses = Common.Request_Handler(
                            URL,
                            Application_JSON_CT=True,
                            Accept_XML=True,
                            Accept_Language_EN_US=True,
                            Filter=True,
                            Host=f"https://www.{Domain}")
                        Response = Responses["Filtered"]
                        Output_file = General.Create_Query_Results_Output_File(
                            Directory, Query, Local_Plugin_Name, Response,
                            Shortcode, The_File_Extensions["Query"])

                        if Output_file:
                            Output_Connections.Output([Main_File, Output_file],
                                                      URL, Title,
                                                      Plugin_Name.lower())
                            Data_to_Cache.append(URL)

                        else:
                            logging.warning(
                                f"{Common.Date()} - {__name__.strip('plugins.')} - Failed to create output file. File may already exist."
                            )

                        Current_Step += 1

            elif Type == "Post":
                from instagramy import InstagramPost
                Local_Plugin_Name = Plugin_Name + "-" + Type
                CSE_Response = InstagramPost(Query)
                JSON_Object = Common.JSON_Handler(vars(CSE_Response))
                CSE_JSON_Output_Response = JSON_Object.Dump_JSON()
                Main_File = General.Main_File_Create(
                    Directory, Local_Plugin_Name, CSE_JSON_Output_Response,
                    Query, The_File_Extensions["Main"])
                Output_Connections = General.Connections(
                    Query, Local_Plugin_Name, Domain, "Social Media - Place",
                    Task_ID, Local_Plugin_Name.lower())
                URL = CSE_Response.url
                Shortcode = URL.replace(f"https://www.{Domain}/p/",
                                        "").replace("/", "")
                Title = "IG | " + General.Get_Title(URL, Requests=True)

                if URL not in Cached_Data and URL not in Data_to_Cache:
                    Responses = Common.Request_Handler(
                        URL,
                        Application_JSON_CT=True,
                        Accept_XML=True,
                        Accept_Language_EN_US=True,
                        Filter=True,
                        Host=f"https://www.{Domain}")
                    Response = Responses["Filtered"]
                    Output_file = General.Create_Query_Results_Output_File(
                        Directory, Query, Local_Plugin_Name, Response,
                        Shortcode, The_File_Extensions["Query"])

                    if Output_file:
                        Output_Connections.Output([Main_File, Output_file],
                                                  URL, Title,
                                                  Plugin_Name.lower())
                        Data_to_Cache.append(URL)

                    else:
                        logging.warning(
                            f"{Common.Date()} - {__name__.strip('plugins.')} - Failed to create output file. File may already exist."
                        )

            else:
                logging.warning(
                    f"{Common.Date()} - {__name__.strip('plugins.')} - Invalid type provided."
                )

        Cached_Data_Object.Write_Cache(Data_to_Cache)

    except Exception as e:
        logging.warning(
            f"{Common.Date()} - {__name__.strip('plugins.')} - {str(e)}")
    print("Extracting...")
except (IndexError, KeyError):
    print("List of username as textfile in argvment")
    sys.exit()

usernames = []
file = open(filename, "r")
for line in file:
    if line != "\n":
        usernames.append(str(line).strip())
followers = []
following = []
posts = []

for username in usernames:
    user = InstagramUser(username)
    followers.append(user.number_of_followers)
    following.append(user.number_of_followings)
    posts.append(user.number_of_posts)

x = np.arange(len(usernames))  # the label locations
width = 0.25  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x + 0.2, followers, width, label="Followers")
rects2 = ax.bar(x, following, width, label="Following")
rects3 = ax.bar(x - 0.2, posts, width, label="Posts")

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel("Popularity")
ax.yaxis.set_visible(True)
예제 #4
0
#pip install instapy
from instagramy import InstagramUser
# Author = TECH_IN_SECONDS

id = input("Enter a Instagram Username = "******"Welcome programmers") 🤖
# 💻 I'm Python Lover 💻
# 📱Android & 🕸 Web Development
# 🤑 Freelancer 🤑
#   🎖 Brand Promotion 🎖
예제 #5
0
def bilgi():
    try:
        user = InstagramUser(subject.get().lower())

        Label(window, text="Tam Adı: ",
              font=("Helvetica", 12)).grid(row=1,
                                           column=0,
                                           sticky=N + S + E + W)
        Label(window, text=user.fullname,
              font=("Helvetica", 12)).grid(row=1,
                                           column=1,
                                           sticky=N + S + E + W)

        Label(window, text="Kullanıcı Adı: ",
              font=("Helvetica", 12)).grid(row=2,
                                           column=0,
                                           sticky=N + S + E + W)
        Label(window, text=user.username,
              font=("Helvetica", 12)).grid(row=2,
                                           column=1,
                                           sticky=N + S + E + W)

        Label(window, text="Takipçi Sayısı: ",
              font=("Helvetica", 12)).grid(row=3,
                                           column=0,
                                           sticky=N + S + E + W)
        Label(window, text=user.number_of_followers,
              font=("Helvetica", 12)).grid(row=3,
                                           column=1,
                                           sticky=N + S + E + W)

        Label(window, text="Takip Edilen Sayısı: ",
              font=("Helvetica", 12)).grid(row=4,
                                           column=0,
                                           sticky=N + S + E + W)
        Label(window, text=user.number_of_followings,
              font=("Helvetica", 12)).grid(row=4,
                                           column=1,
                                           sticky=N + S + E + W)

        Label(window, text="Post Sayısı: ",
              font=("Helvetica", 12)).grid(row=5,
                                           column=0,
                                           sticky=N + S + E + W)
        Label(window, text=user.number_of_posts,
              font=("Helvetica", 12)).grid(row=5,
                                           column=1,
                                           sticky=N + S + E + W)

        Label(window, text="Gizli mi: ",
              font=("Helvetica", 12)).grid(row=6,
                                           column=0,
                                           sticky=N + S + E + W)
        if user.is_private:
            Label(window, text="Evet",
                  font=("Helvetica", 12)).grid(row=6,
                                               column=1,
                                               sticky=N + S + E + W)
        else:
            Label(window, text="Hayır",
                  font=("Helvetica", 12)).grid(row=6,
                                               column=1,
                                               sticky=N + S + E + W)

        Label(window, text="Doğrulanmış mı: ",
              font=("Helvetica", 12)).grid(row=7,
                                           column=0,
                                           sticky=N + S + E + W)
        if user.is_verified:
            Label(window, text="Evet",
                  font=("Helvetica", 12)).grid(row=7,
                                               column=1,
                                               sticky=N + S + E + W)
        else:
            Label(window, text="Hayır",
                  font=("Helvetica", 12)).grid(row=7,
                                               column=1,
                                               sticky=N + S + E + W)

        Label(window,
              text="-----------------------------------------",
              font=("Helvetica", 12)).grid(row=8,
                                           column=0,
                                           sticky=N + S + E + W)

        Label(window, text="Biyografi: ",
              font=("Helvetica", 12)).grid(row=9,
                                           column=0,
                                           sticky=N + S + E + W)
        Label(window, text=user.biography,
              font=("Helvetica", 12)).grid(row=9,
                                           column=1,
                                           sticky=N + S + E + W)
    except:
        messagebox.showerror("Error!",
                             "Lütfen geçerli bir kullanıcı adı giriniz.")
from bs4 import BeautifulSoup
from instagramy import InstagramUser
import pandas as pd
import requests

session_id = "17889d0ff99-2360a0"

user = InstagramUser('prateekpamecha1511', sessionid=session_id)
userdata = []
userdata.append({
    'followers': user.number_of_followers,
    'follows': user.number_of_followings,
    'full_name': user.fullname,
    'profile_pic_url': user.profile_picture_url,
    'username': user.username
})
#joblist=[]

#c=extract(0..)

df = pd.DataFrame(userdata)
print(df.head())
df.to_csv('userdata.csv')
예제 #7
0
async def inst(event):
    user = InstagramUser(event.text)
    await event.respond(
        f'Подписчиков: {user.number_of_followers}, Подписок: {user.number_of_followings}, Публикаций: {user.number_of_posts}'
    )
예제 #8
0
def test_user():
    user = InstagramUser('github')
    assert user.username == "github"