Ejemplo n.º 1
0
def test_tag():
    tag_name = 'cat'
    res = ie.tag(tag_name)
    assert isinstance(res, tuple)
    assert isinstance(res.data, dict)
    assert isinstance(res.cursor, six.string_types)
    time.sleep(1)
    data, _ = ie.tag(tag_name, res.cursor)
    assert isinstance(data, dict)
Ejemplo n.º 2
0
    def run(self):
        data, cursor = ie.tag(self.term)
        edges = data['edge_hashtag_to_media']['edges']  
        posts = []
        for post in edges:
            body = post['node']['edge_media_to_caption']['edges'][0]['node']['text']
            text = TextBlob(body)
            sentiment = text.sentiment
            b = {
                "id":post['node']['id'],
                "body": body,
                "display_url": post['node']['display_url'],
                "caption": post['node']['accessibility_caption'],
                "sentiment": sentiment
                


            }
            posts.append(b)
        return posts
Ejemplo n.º 3
0
def Search(Query_List, Task_ID, Type, **kwargs):
    Data_to_Cache = []
    Cached_Data = []

    if kwargs.get('Limit'):

        if int(kwargs["Limit"]) > 0:
            Limit = kwargs["Limit"]

        else:
            Limit = 10

    else:
        Limit = 10

    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 = General.Get_Cache(Directory, Plugin_Name)

    if not Cached_Data:
        Cached_Data = []

    Query_List = General.Convert_to_List(Query_List)

    for Query in Query_List:

        if Type == "User":
            Local_Plugin_Name = Plugin_Name + "-" + Type
            CSE_Response = instagram_explore.user(Query)
            CSE_JSON_Output_Response = json.dumps(CSE_Response, indent=4, sort_keys=True)
            Output_file = General.Main_File_Create(Directory, Local_Plugin_Name, CSE_JSON_Output_Response, Query, ".json")
            Posts = CSE_Response[0]["edge_owner_to_timeline_media"]["edges"]
            Output_Connections = General.Connections(Query, Local_Plugin_Name, "instagram.com", "Data Leakage", Task_ID, Local_Plugin_Name.lower())
            Current_Step = 0

            for Post in Posts:
                Shortcode = Post["node"]["shortcode"]
                URL = "https://www.instagram.com/p/" + Shortcode + "/"

                if URL not in Cached_Data and URL not in Data_to_Cache and Current_Step < int(Limit):

                    if Output_file:
                        Output_Connections.Output(Output_file, URL, General.Get_Title(URL))

                Data_to_Cache.append(URL)
                Current_Step += 1

        elif Type == "Tag":
            Local_Plugin_Name = Plugin_Name + "-" + Type
            CSE_Response = instagram_explore.tag(Query)
            CSE_JSON_Output_Response = json.dumps(CSE_Response, indent=4, sort_keys=True)
            Output_file = General.Main_File_Create(Directory, Local_Plugin_Name, CSE_JSON_Output_Response, Query, ".json")
            Posts = CSE_Response[0]["edge_hashtag_to_media"]["edges"]
            Output_Connections = General.Connections(Query, Local_Plugin_Name, "instagram.com", "Data Leakage", Task_ID, Local_Plugin_Name.lower())
            Current_Step = 0

            for Post in Posts:
                Shortcode = Post["node"]["shortcode"]
                URL = "https://www.instagram.com/p/" + Shortcode + "/"

                if URL not in Cached_Data and URL not in Data_to_Cache and Current_Step < int(Limit):

                    if Output_file:
                        Output_Connections.Output(Output_file, URL, General.Get_Title(URL))

                Data_to_Cache.append(URL)
                Current_Step += 1

        elif Type == "Location":
            Local_Plugin_Name = Plugin_Name + "-" + Type
            CSE_Response = location(Query)
            CSE_JSON_Output_Response = json.dumps(CSE_Response, indent=4, sort_keys=True)
            Output_file = General.Main_File_Create(Directory, Local_Plugin_Name, CSE_JSON_Output_Response, Query, ".json")
            Posts = CSE_Response[0]["edge_location_to_media"]["edges"]
            Output_Connections = General.Connections(Query, Local_Plugin_Name, "instagram.com", "Data Leakage", Task_ID, Local_Plugin_Name.lower())
            Current_Step = 0

            for Post in Posts:
                Shortcode = Post["node"]["shortcode"]
                URL = "https://www.instagram.com/p/" + Shortcode + "/"

                if URL not in Cached_Data and URL not in Data_to_Cache and Current_Step < int(Limit):

                    if Output_file:
                        Output_Connections.Output(Output_file, URL, General.Get_Title(URL))

                Data_to_Cache.append(URL)
                Current_Step += 1

        elif Type == "Media":
            Local_Plugin_Name = Plugin_Name + "-" + Type
            CSE_Response = instagram_explore.media(Query)

            if CSE_Response:
                CSE_JSON_Output_Response = json.dumps(CSE_Response, indent=4, sort_keys=True)
                Output_file = General.Main_File_Create(Directory, Local_Plugin_Name, CSE_JSON_Output_Response, Query, ".json")
                URL = "https://www.instagram.com/p/" + Query + "/"

                if URL not in Cached_Data and URL not in Data_to_Cache:

                    if Output_file:
                        Output_Connections = General.Connections(Query, Local_Plugin_Name, "instagram.com", "Data Leakage", Task_ID, Local_Plugin_Name.lower())
                        Output_Connections.Output(Output_file, URL, General.Get_Title(URL))

                Data_to_Cache.append(URL)

            else:
                logging.warning(General.Date() + " - " + __name__.strip('plugins.') + " - Invalid response.")

        else:
            logging.warning(General.Date() + " - " + __name__.strip('plugins.') + " - Invalid type provided.")

    if Cached_Data:
        General.Write_Cache(Directory, Data_to_Cache, Plugin_Name, "a")

    else:
        General.Write_Cache(Directory, Data_to_Cache, Plugin_Name, "w")
class HashTagSearchExample(HashTagSearch):
    def __init__(self):
        super().__init__()
        self.total_posts = 0

    def save_results(self, instagram_results):
        super().save_results(instagram_results)
        for i, post in enumerate(instagram_results):
            self.total_posts += 1
            print("%i - %s" % (self.total_posts, post.processed_text()))

import instagram_explore as ie

# Search tag name
res = ie.tag('cat')
print(res.data)                   # All

# Next page
data, cursor = ie.tag('cat', res.cursor)

# Image only
images = ie.tag_images('cat').data


import instagram_explore as ie

# Search location id
res = ie.location('213163910')
print(res.data)
Ejemplo n.º 5
0
print(
    "run stalkSetup.py before the first time running this, only need to run it once"
)
import instagram_explore as ie
from instabot import Bot
import urllib
image = urllib.request.URLopener()

bot = Bot()

boobTag = input("From what hashtag? ")
result = ie.tag(boobTag)

bot.login(username="******", password="******")

boobCount = input("How many boobs?")

for i in range(int(boobCount)):
    try:
        sexy = result.data['edge_hashtag_to_top_posts']['edges'][i]['node'][
            'thumbnail_src']
        imgName = (str(i) + ".jpg")
        image.retrieve(sexy, imgName)
    except:
        print("no worky worky")
Ejemplo n.º 6
0
def Search(Query_List, Task_ID, Type, **kwargs):

    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 = General.Get_Cache(Directory, Plugin_Name)
        Query_List = General.Convert_to_List(Query_List)
        Limit = General.Get_Limit(kwargs)

        for Query in Query_List:

            if Type == "User":
                Local_Plugin_Name = Plugin_Name + "-" + Type
                CSE_Response = instagram_explore.user(Query)
                CSE_JSON_Output_Response = json.dumps(CSE_Response,
                                                      indent=4,
                                                      sort_keys=True)
                Main_File = General.Main_File_Create(
                    Directory, Local_Plugin_Name, CSE_JSON_Output_Response,
                    Query, The_File_Extensions["Main"])
                Posts = CSE_Response[0]["edge_owner_to_timeline_media"][
                    "edges"]
                Output_Connections = General.Connections(
                    Query, Local_Plugin_Name,
                    "instagram.com", "Social Media - Person", Task_ID,
                    Local_Plugin_Name.lower())
                Current_Step = 0

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

                    if URL not in Cached_Data and URL not in Data_to_Cache and Current_Step < int(
                            Limit):
                        Response = requests.get(URL, headers=headers).text
                        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"{General.Date()} - {__name__.strip('plugins.')} - Failed to create output file. File may already exist."
                            )

                        Current_Step += 1

            elif Type == "Tag":
                Local_Plugin_Name = Plugin_Name + "-" + Type
                CSE_Response = instagram_explore.tag(Query)
                CSE_JSON_Output_Response = json.dumps(CSE_Response,
                                                      indent=4,
                                                      sort_keys=True)
                Main_File = General.Main_File_Create(
                    Directory, Local_Plugin_Name, CSE_JSON_Output_Response,
                    Query, The_File_Extensions["Main"])
                Posts = CSE_Response[0]["edge_hashtag_to_media"]["edges"]
                Output_Connections = General.Connections(
                    Query, Local_Plugin_Name,
                    "instagram.com", "Social Media - Person", Task_ID,
                    Local_Plugin_Name.lower())
                Current_Step = 0

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

                    if URL not in Cached_Data and URL not in Data_to_Cache and Current_Step < int(
                            Limit):
                        Response = requests.get(URL, headers=headers).text
                        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"{General.Date()} - {__name__.strip('plugins.')} - Failed to create output file. File may already exist."
                            )

                        Current_Step += 1

            elif Type == "Location":
                Local_Plugin_Name = Plugin_Name + "-" + Type
                CSE_Response = location(Query)
                CSE_JSON_Output_Response = json.dumps(CSE_Response,
                                                      indent=4,
                                                      sort_keys=True)
                Main_File = General.Main_File_Create(
                    Directory, Local_Plugin_Name, CSE_JSON_Output_Response,
                    Query, The_File_Extensions["Main"])
                Posts = CSE_Response[0]["edge_location_to_media"]["edges"]
                Output_Connections = General.Connections(
                    Query, Local_Plugin_Name, "instagram.com",
                    "Social Media - Place", Task_ID, Local_Plugin_Name.lower())
                Current_Step = 0

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

                    if URL not in Cached_Data and URL not in Data_to_Cache and Current_Step < int(
                            Limit):
                        Response = requests.get(URL, headers=headers).text
                        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"{General.Date()} - {__name__.strip('plugins.')} - Failed to create output file. File may already exist."
                            )

                        Current_Step += 1

            elif Type == "Media":
                Local_Plugin_Name = Plugin_Name + "-" + Type
                CSE_Response = instagram_explore.media(Query)

                if CSE_Response:
                    CSE_JSON_Output_Response = json.dumps(CSE_Response,
                                                          indent=4,
                                                          sort_keys=True)
                    Main_File = General.Main_File_Create(
                        Directory, Local_Plugin_Name, CSE_JSON_Output_Response,
                        Query, The_File_Extensions["Main"])
                    URL = f"https://www.instagram.com/p/{Query}/"
                    Title = "IG | " + General.Get_Title(URL)

                    if URL not in Cached_Data and URL not in Data_to_Cache:
                        Response = requests.get(URL, headers=headers).text
                        Output_file = General.Create_Query_Results_Output_File(
                            Directory, Query, Local_Plugin_Name, Response,
                            Shortcode, The_File_Extensions["Query"])

                        if Output_file:
                            Output_Connections = General.Connections(
                                Query, Local_Plugin_Name, "instagram.com",
                                "Social Media - Media", Task_ID,
                                Local_Plugin_Name.lower())
                            Output_Connections.Output([Main_File, Output_file],
                                                      URL, Title,
                                                      Plugin_Name.lower())
                            Data_to_Cache.append(URL)

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

                else:
                    logging.warning(
                        f"{General.Date()} - {__name__.strip('plugins.')} - Invalid response."
                    )

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

        if Cached_Data:
            General.Write_Cache(Directory, Data_to_Cache, Plugin_Name, "a")

        else:
            General.Write_Cache(Directory, Data_to_Cache, Plugin_Name, "w")

    except Exception as e:
        logging.warning(
            f"{General.Date()} - {__name__.strip('plugins.')} - {str(e)}")