'''
    instahunter.py

    Author: Araekiel
    Copyright:  Copyright © 2019, Araekiel
    License: MIT
    Version: 1.6.3
'''

import click
import requests
import json
from datetime import datetime


@click.group()
def cli():
    """Made by Araekiel | v1.6.3"""

headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0"}

@click.command()
@click.option('-tag', prompt="Hashtag", help="The hashtag you want to search the posts with")
@click.option('--post-type', default="latest", help="latest: Get latest posts | top: Get top posts")
@click.option('-create-file', default="false", help="true: Create a file with the data | false: Will not create a file, false is default")
@click.option('--file-type', default="text", help="json: Create a json file | text: Create a text file, text is default")
def getposts(tag, post_type, create_file, file_type):
    """This command will fetch latest or top public posts with a Hashtag"""
    try:
        # Creating file if required, creating array json_data to store data if the file type is json
        if(create_file == "true"):
            if(file_type == "json"):
                file = open(tag+"_posts.json", "w+")
                json_data = []
            else:
                file = open(tag+"_posts.txt", "w+", encoding="utf-8")
        counter = 0
        api_url = "https://www.instagram.com/explore/tags/%s/?__a=1" % tag
        req = requests.get(url=api_url, headers=headers)
        data = req.json()
        
        if(post_type == "top"):
            edges = data["graphql"]["hashtag"]["edge_hashtag_to_top_posts"]["edges"]
        else:
            edges = data["graphql"]["hashtag"]["edge_hashtag_to_media"]["edges"]

        # Looping through 'edges' in the data acquired
        for edge in edges:
            counter = counter + 1
            # Collecting necessary data from each edge
            try:
                caption = edge["node"]["edge_media_to_caption"]["edges"][0]["node"]["text"]
            except:
                caption = "No Caption"
            scraped_data = {
                "id": counter,
                "post_id": edge["node"]["id"],
                "shortcode": edge["node"]["shortcode"],
                "owner_id": edge["node"]["owner"]["id"],
                "display_url": edge["node"]["display_url"],
                "caption": caption,
                "time": str(datetime.fromtimestamp(
                    edge["node"]["taken_at_timestamp"])),
                "n_likes": edge["node"]["edge_liked_by"]["count"],
                "n_comments": edge["node"]["edge_media_to_comment"]["count"],
                "is_video": edge["node"]["is_video"]
            }
            if(create_file == "true"):
                # If the file type is json then appending the data to json_data array instead of writing it to the file right away
                if(file_type == "json"):
                    json_data.append(scraped_data)
                else:
                    file.write("###############################\nID: %s \nPost ID: %s \nShortcode: %s \nOwner ID: %s \nDisplay URL: %s \nCaption: %s \nTime: %s \nNumber of likes: %s \nNumber of comments: %s \nIs Video: %s \n###############################\n\n\n\n\n" % (
                        str(counter), str(scraped_data["post_id"]), str(scraped_data["shortcode"]), str(scraped_data["owner_id"]), str(scraped_data["display_url"]), str(scraped_data["caption"]), str(scraped_data["time"]), str(scraped_data["n_likes"]), str(scraped_data["n_comments"]), str(scraped_data["is_video"])))
            else:
                click.echo("###############################\nID: %s \nPost ID: %s \nShortcode: %s \nOwner ID: %s \nDisplay URL: %s \nCaption: %s \nTime: %s \nNumber of likes: %s \nNumber of comments: %s \nIs Video: %s \n###############################\n\n\n\n\n" % (
                    counter, scraped_data["post_id"], scraped_data["shortcode"], scraped_data["owner_id"], scraped_data["display_url"], scraped_data["caption"], scraped_data["time"], scraped_data["n_likes"], scraped_data["n_comments"], scraped_data["is_video"]))
        if(create_file == "true"):
            # Closing the file and dumping the data before closing if the file type is json
            if(file_type == "json"):
                json.dump(json_data, file)
                click.echo("File Created, name: '%s_posts.json'" % tag)
            else:
                click.echo("File Created, name: '%s_posts.txt" % tag)
            file.close()
        else:
            click.echo("Done!")
    except:
        click.echo(
            "Couldn't retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection")

@click.command()
@click.option('-username', prompt="Username", help="Username you want to search the user with")
@click.option('-create-file', default="false", help="true: Create a file with the data | false: Will not create a file, false is default")
@click.option('--file-type', default="text", help="json: Create a json file | text: Create a text file, text is default")
def getuser(username, create_file, file_type):
    """This command will fetch user data with a Username"""

    api_url = "https://www.instagram.com/%s/?__a=1" % username

    try:
        req = requests.get(url=api_url, headers=headers)
        data = req.json()
        # Collecting necessary data
        user = data["graphql"]["user"]
        if(user["highlight_reel_count"] > 0):
            has_highlights = True
        else:
            has_highlights = False
        scraped_data = {
            "user_id": user["id"],
            "username": user["username"],
            "full_name": user["full_name"],
            "profile_pic_url": user["profile_pic_url_hd"],
            "bio": user["biography"],
            "n_uploads": user["edge_owner_to_timeline_media"]["count"],
            "n_followers": user["edge_followed_by"]["count"],
            "n_following": user["edge_follow"]["count"],
            "is_private": user["is_private"],
            "is_verified": user["is_verified"],
            "external_url": user["external_url"],
            "igtv_videos": user["edge_felix_video_timeline"]["count"],
            "has_highlights": has_highlights
        }
        if(create_file == "true"):
            if(file_type == "json"):
                file = open(username+"_user.json", "w+")
                json.dump(scraped_data, file)
                file.close()
                click.echo("File Created, name: '%s_user.json'" % str(username))
            else:
                file = open(username+"_user.txt", "w+", encoding="utf-8")
                file.write("User ID: %s \nUsername: %s \nFull Name: %s \nProfile Pic URL: %s \nBio: %s \nUploads: %s \nFollowers: %s \nFollowing: %s \nPrivate ID: %s \nVerified ID: %s \nExternal URL: %s \nIGTV videos: %s \nHas highlights: %s" % (
                    str(scraped_data["user_id"]), scraped_data["username"], scraped_data["full_name"], scraped_data["profile_pic_url"], scraped_data["bio"], str(scraped_data["n_uploads"]), str(scraped_data["n_followers"]), str(scraped_data["n_following"]), str(scraped_data["is_private"]), str(scraped_data["is_verified"]), scraped_data["external_url"], str(scraped_data["igtv_videos"]), str(scraped_data["has_highlights"])))
                file.close()
                click.echo("File Created, name: '%s_user.txt'" % str(username))
        else:
            click.echo("User ID: %s \nUsername: %s \nFull Name: %s \nProfile Pic URL: %s \nBio: %s \nUploads: %s \nFollowers: %s \nFollowing: %s \nPrivate ID: %s \nVerified ID: %s \nExternal URL: %s \nIGTV videos: %s \nHas highlights: %s" % (
                str(scraped_data["user_id"]), scraped_data["username"], scraped_data["full_name"], scraped_data["profile_pic_url"], scraped_data["bio"], str(scraped_data["n_uploads"]), str(scraped_data["n_followers"]), str(scraped_data["n_following"]), str(scraped_data["is_private"]), str(scraped_data["is_verified"]), scraped_data["external_url"], str(scraped_data["igtv_videos"]), str(scraped_data["has_highlights"])))
            click.echo('Done!')
    except:
        click.echo(
            "Couldn't retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection")


@click.command()
@click.option('-username', prompt="Username", help='The username of the user you want to search the user id of')
@click.option('-create-file', default="false", help="true: Create a file with the data | false: Will not create a file, false is default")
@click.option('--file-type', default="text", help="json: Create a json file | text: Create a text file, text is default")
def getuserposts(username, create_file, file_type):
    """This command will fetch recent posts of a user with a Username"""
    try:
        # Creating file if required, creating array json_data to store data if the file type is json
        if(create_file == "true"):
            if(file_type == "json"):
                file = open(username+"_posts.json", "w+")
                json_data = []
            else:
                file = open(username+"_posts.txt", "w+", encoding="utf-8")
        counter = 0
        api_url = "https://www.instagram.com/%s/?__a=1" % username
        req = requests.get(url=api_url, headers=headers)
        data = req.json()
        posts = data["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"]
        # Looping through posts
        for post in posts:
            counter = counter + 1
            node = post["node"]
            # Collecting necessary data
            try:
                caption = node["edge_media_to_caption"]["edges"][0]["node"]["text"]
            except:
                caption = ""
            try:
                location = node["location"]["name"]
            except:
                location = "No Location"
            scraped_data = {
                "id": counter,
                "post_id": node["id"],
                "shortcode": node["shortcode"],
                "display_url": node["display_url"],
                "height": node["dimensions"]["height"],
                "width": node["dimensions"]["width"],
                "caption": caption,
                "time": str(datetime.fromtimestamp(node["taken_at_timestamp"])),
                "n_likes": node["edge_liked_by"]["count"],
                "comments_disabled": node["comments_disabled"],
                "n_comments": node["edge_media_to_comment"]["count"],
                "location": location,
                "is_video": node["is_video"]
            }
            if(create_file == "true"):
                if(file_type == "json"):
                    # If the file type is json then appending the data to json_data array instead of writing it to the file right away
                    json_data.append(scraped_data)
                else:
                    file.write("###############################\nID: %s \nPost ID: %s \nShortcode: %s \nDisplay URL: %s \nImage Height: %s \nImage Width: %s \nCaption: %s \nTime: %s \nNumber of likes: %s \nComments Disabled: %s \nNumber of comments: %s \nLocation: %s \nIs Video: %s \n###############################\n\n\n\n\n" % (
                        str(counter), str(scraped_data["post_id"]), str(scraped_data["shortcode"]), str(scraped_data["display_url"]), str(scraped_data["height"]), str(scraped_data["width"]), str(scraped_data["caption"]), str(scraped_data["time"]), str(scraped_data["n_likes"]), str(scraped_data["comments_disabled"]), str(scraped_data["n_comments"]), str(scraped_data["location"]), str(scraped_data["is_video"])))
            else:
                click.echo("###############################\nID: %s \nPost ID: %s \nShortcode: %s \nDisplay URL: %s \nImage Height: %s \nImage Width: %s \nCaption: %s \nTime: %s \nNumber of likes: %s \nComments Disabled: %s \nNumber of comments: %s \nLocation: %s \nIs Video: %s \n###############################\n\n\n\n\n" % (
                    str(counter), str(scraped_data["post_id"]), str(scraped_data["shortcode"]), str(scraped_data["display_url"]), str(scraped_data["height"]), str(scraped_data["width"]), str(scraped_data["caption"]), str(scraped_data["time"]), str(scraped_data["n_likes"]), str(scraped_data["comments_disabled"]), str(scraped_data["n_comments"]), str(scraped_data["location"]), str(scraped_data["is_video"])))
        if(create_file == "true"):
            # Closing the file and dumping the data before closing if the file type is json
            if(file_type == "json"):
                json.dump(json_data, file)
                click.echo("File Created, name: '%s_posts.json'" % username)
            else:
                click.echo("File Created, name: '%s_posts.txt" % username)
            file.close()
        else:
            click.echo("Done!")
    except:
        click.echo(
            "Couldn't retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection")


@click.command()
@click.option('-query', prompt="Query", help="The term you want to search users with")
@click.option('-create-file', default="false", help="true: Create a file with the data | false: Will not create a file, false is default")
@click.option('--file-type', default="text", help="json: Create a json file | text: Create a text file, text is default")
def search(query, create_file, file_type):
    """This command searches for users on instagram"""
    try:
        if(create_file == "true"):
            if(file_type == "json"):
                file = open(query+"_users.json", "w+")
                json_data = []
            else:
                file = open(query+"_users.text",
                            "w+", encoding="utf-8")
        counter = 0
        api_url = "https://www.instagram.com/web/search/topsearch/?query=%s" % query
        req = requests.get(api_url, headers=headers)
        data = req.json()
        users = data["users"]
        for user in users:
            counter = counter + 1
            scraped_data = {
                "id": counter,
                "user_id": user["user"]["pk"],
                "username": user["user"]["username"],
                "full_name": user["user"]["full_name"],
                "profile_pic_url": user["user"]["profile_pic_url"],
                "is_private": user["user"]["is_private"],
                "is_verified": user["user"]["is_verified"],
            }
            if(create_file == "true"):
                # If the file type is json then appending the data to json_data array instead of writing it to the file right away
                if(file_type == "json"):
                    json_data.append(scraped_data)
                else:
                    file.write("###############################\nID: %s \nUser ID: %s \nUsername: %s \nFull Name: %s \nProfile Pic URL: %s \nPrivate ID: %s \nVerified ID: %s \n###############################\n\n\n\n\n" % (str(counter), str(
                        scraped_data["user_id"]), str(scraped_data["username"]), str(scraped_data["full_name"]), str(scraped_data["profile_pic_url"]), str(scraped_data["is_private"]), str(scraped_data["is_verified"])))
            else:
                click.echo("###############################\nID: %s \nUser ID: %s \nUsername: %s \nFull Name: %s \nProfile Pic URL: %s \nPrivate ID: %s \nVerified ID: %s \n###############################\n\n\n\n\n" % (str(counter), str(
                    scraped_data["user_id"]), str(scraped_data["username"]), str(scraped_data["full_name"]), str(scraped_data["profile_pic_url"]), str(scraped_data["is_private"]), str(scraped_data["is_verified"])))
        if(create_file == "true"):
            # Closing the file and dumping the data before closing if the file type is json
            if(file_type == "json"):
                json.dump(json_data, file)
                click.echo("File Created, name: '%s_users.json'" %
                           query)
            else:
                click.echo("File Created, name: '%s_users.txt'" %
                           query)
            file.close()
        else:
            click.echo("Done!")
    except:
        click.echo(
            "Couldn't retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection")


cli.add_command(getposts)
cli.add_command(getuser)
cli.add_command(getuserposts)
cli.add_command(search)

if __name__ == "__main__":
    cli()

[((203, 216), 'click.group', 'click.group', ([], {}), '()\n', (214, 216), False, 'import click\n'), ((379, 394), 'click.command', 'click.command', ([], {}), '()\n', (392, 394), False, 'import click\n'), ((396, 493), 'click.option', 'click.option', (['"""-tag"""'], {'prompt': '"""Hashtag"""', 'help': '"""The hashtag you want to search the posts with"""'}), "('-tag', prompt='Hashtag', help=\n    'The hashtag you want to search the posts with')\n", (408, 493), False, 'import click\n'), ((490, 594), 'click.option', 'click.option', (['"""--post-type"""'], {'default': '"""latest"""', 'help': '"""latest: Get latest posts | top: Get top posts"""'}), "('--post-type', default='latest', help=\n    'latest: Get latest posts | top: Get top posts')\n", (502, 594), False, 'import click\n'), ((591, 738), 'click.option', 'click.option', (['"""-create-file"""'], {'default': '"""false"""', 'help': '"""true: Create a file with the data | false: Will not create a file, false is default"""'}), "('-create-file', default='false', help=\n    'true: Create a file with the data | false: Will not create a file, false is default'\n    )\n", (603, 738), False, 'import click\n'), ((730, 855), 'click.option', 'click.option', (['"""--file-type"""'], {'default': '"""text"""', 'help': '"""json: Create a json file | text: Create a text file, text is default"""'}), "('--file-type', default='text', help=\n    'json: Create a json file | text: Create a text file, text is default')\n", (742, 855), False, 'import click\n'), ((4798, 4813), 'click.command', 'click.command', ([], {}), '()\n', (4811, 4813), False, 'import click\n'), ((4815, 4914), 'click.option', 'click.option', (['"""-username"""'], {'prompt': '"""Username"""', 'help': '"""Username you want to search the user with"""'}), "('-username', prompt='Username', help=\n    'Username you want to search the user with')\n", (4827, 4914), False, 'import click\n'), ((4911, 5058), 'click.option', 'click.option', (['"""-create-file"""'], {'default': '"""false"""', 'help': '"""true: Create a file with the data | false: Will not create a file, false is default"""'}), "('-create-file', default='false', help=\n    'true: Create a file with the data | false: Will not create a file, false is default'\n    )\n", (4923, 5058), False, 'import click\n'), ((5050, 5175), 'click.option', 'click.option', (['"""--file-type"""'], {'default': '"""text"""', 'help': '"""json: Create a json file | text: Create a text file, text is default"""'}), "('--file-type', default='text', help=\n    'json: Create a json file | text: Create a text file, text is default')\n", (5062, 5175), False, 'import click\n'), ((8442, 8457), 'click.command', 'click.command', ([], {}), '()\n', (8455, 8457), False, 'import click\n'), ((8459, 8575), 'click.option', 'click.option', (['"""-username"""'], {'prompt': '"""Username"""', 'help': '"""The username of the user you want to search the user id of"""'}), "('-username', prompt='Username', help=\n    'The username of the user you want to search the user id of')\n", (8471, 8575), False, 'import click\n'), ((8572, 8719), 'click.option', 'click.option', (['"""-create-file"""'], {'default': '"""false"""', 'help': '"""true: Create a file with the data | false: Will not create a file, false is default"""'}), "('-create-file', default='false', help=\n    'true: Create a file with the data | false: Will not create a file, false is default'\n    )\n", (8584, 8719), False, 'import click\n'), ((8711, 8836), 'click.option', 'click.option', (['"""--file-type"""'], {'default': '"""text"""', 'help': '"""json: Create a json file | text: Create a text file, text is default"""'}), "('--file-type', default='text', help=\n    'json: Create a json file | text: Create a text file, text is default')\n", (8723, 8836), False, 'import click\n'), ((13200, 13215), 'click.command', 'click.command', ([], {}), '()\n', (13213, 13215), False, 'import click\n'), ((13217, 13307), 'click.option', 'click.option', (['"""-query"""'], {'prompt': '"""Query"""', 'help': '"""The term you want to search users with"""'}), "('-query', prompt='Query', help=\n    'The term you want to search users with')\n", (13229, 13307), False, 'import click\n'), ((13304, 13451), 'click.option', 'click.option', (['"""-create-file"""'], {'default': '"""false"""', 'help': '"""true: Create a file with the data | false: Will not create a file, false is default"""'}), "('-create-file', default='false', help=\n    'true: Create a file with the data | false: Will not create a file, false is default'\n    )\n", (13316, 13451), False, 'import click\n'), ((13443, 13568), 'click.option', 'click.option', (['"""--file-type"""'], {'default': '"""text"""', 'help': '"""json: Create a json file | text: Create a text file, text is default"""'}), "('--file-type', default='text', help=\n    'json: Create a json file | text: Create a text file, text is default')\n", (13455, 13568), False, 'import click\n'), ((1444, 1486), 'requests.get', 'requests.get', ([], {'url': 'api_url', 'headers': 'headers'}), '(url=api_url, headers=headers)\n', (1456, 1486), False, 'import requests\n'), ((5366, 5408), 'requests.get', 'requests.get', ([], {'url': 'api_url', 'headers': 'headers'}), '(url=api_url, headers=headers)\n', (5378, 5408), False, 'import requests\n'), ((9422, 9464), 'requests.get', 'requests.get', ([], {'url': 'api_url', 'headers': 'headers'}), '(url=api_url, headers=headers)\n', (9434, 9464), False, 'import requests\n'), ((14067, 14105), 'requests.get', 'requests.get', (['api_url'], {'headers': 'headers'}), '(api_url, headers=headers)\n', (14079, 14105), False, 'import requests\n'), ((4550, 4569), 'click.echo', 'click.echo', (['"""Done!"""'], {}), "('Done!')\n", (4560, 4569), False, 'import click\n'), ((4590, 4793), 'click.echo', 'click.echo', (['"""Couldn\'t retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection"""'], {}), '(\n    """Couldn\'t retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection"""\n    )\n', (4600, 4793), False, 'import click\n'), ((8193, 8212), 'click.echo', 'click.echo', (['"""Done!"""'], {}), "('Done!')\n", (8203, 8212), False, 'import click\n'), ((8233, 8436), 'click.echo', 'click.echo', (['"""Couldn\'t retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection"""'], {}), '(\n    """Couldn\'t retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection"""\n    )\n', (8243, 8436), False, 'import click\n'), ((12951, 12970), 'click.echo', 'click.echo', (['"""Done!"""'], {}), "('Done!')\n", (12961, 12970), False, 'import click\n'), ((12991, 13194), 'click.echo', 'click.echo', (['"""Couldn\'t retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection"""'], {}), '(\n    """Couldn\'t retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection"""\n    )\n', (13001, 13194), False, 'import click\n'), ((16331, 16350), 'click.echo', 'click.echo', (['"""Done!"""'], {}), "('Done!')\n", (16341, 16350), False, 'import click\n'), ((16371, 16574), 'click.echo', 'click.echo', (['"""Couldn\'t retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection"""'], {}), '(\n    """Couldn\'t retrieve data, One of the following was the issue: \n1. Your query was wrong \n2. Instagram servers did not respond \n3. There is a problem with your internet connection"""\n    )\n', (16381, 16574), False, 'import click\n'), ((3618, 4122), 'click.echo', 'click.echo', (['("""###############################\nID: %s \nPost ID: %s \nShortcode: %s \nOwner ID: %s \nDisplay URL: %s \nCaption: %s \nTime: %s \nNumber of likes: %s \nNumber of comments: %s \nIs Video: %s \n###############################\n\n\n\n\n"""\n     % (counter, scraped_data[\'post_id\'], scraped_data[\'shortcode\'],\n    scraped_data[\'owner_id\'], scraped_data[\'display_url\'], scraped_data[\n    \'caption\'], scraped_data[\'time\'], scraped_data[\'n_likes\'], scraped_data\n    [\'n_comments\'], scraped_data[\'is_video\']))'], {}), '(\n    """###############################\nID: %s \nPost ID: %s \nShortcode: %s \nOwner ID: %s \nDisplay URL: %s \nCaption: %s \nTime: %s \nNumber of likes: %s \nNumber of comments: %s \nIs Video: %s \n###############################\n\n\n\n\n"""\n     % (counter, scraped_data[\'post_id\'], scraped_data[\'shortcode\'],\n    scraped_data[\'owner_id\'], scraped_data[\'display_url\'], scraped_data[\n    \'caption\'], scraped_data[\'time\'], scraped_data[\'n_likes\'], scraped_data\n    [\'n_comments\'], scraped_data[\'is_video\']))\n', (3628, 4122), False, 'import click\n'), ((4312, 4338), 'json.dump', 'json.dump', (['json_data', 'file'], {}), '(json_data, file)\n', (4321, 4338), False, 'import json\n'), ((4355, 4410), 'click.echo', 'click.echo', (['("File Created, name: \'%s_posts.json\'" % tag)'], {}), '("File Created, name: \'%s_posts.json\'" % tag)\n', (4365, 4410), False, 'import click\n'), ((4445, 4498), 'click.echo', 'click.echo', (['("File Created, name: \'%s_posts.txt" % tag)'], {}), '("File Created, name: \'%s_posts.txt" % tag)\n', (4455, 4498), False, 'import click\n'), ((6488, 6517), 'json.dump', 'json.dump', (['scraped_data', 'file'], {}), '(scraped_data, file)\n', (6497, 6517), False, 'import json\n'), ((12703, 12729), 'json.dump', 'json.dump', (['json_data', 'file'], {}), '(json_data, file)\n', (12712, 12729), False, 'import json\n'), ((12746, 12806), 'click.echo', 'click.echo', (['("File Created, name: \'%s_posts.json\'" % username)'], {}), '("File Created, name: \'%s_posts.json\'" % username)\n', (12756, 12806), False, 'import click\n'), ((12841, 12899), 'click.echo', 'click.echo', (['("File Created, name: \'%s_posts.txt" % username)'], {}), '("File Created, name: \'%s_posts.txt" % username)\n', (12851, 12899), False, 'import click\n'), ((16034, 16060), 'json.dump', 'json.dump', (['json_data', 'file'], {}), '(json_data, file)\n', (16043, 16060), False, 'import json\n'), ((16077, 16134), 'click.echo', 'click.echo', (['("File Created, name: \'%s_users.json\'" % query)'], {}), '("File Created, name: \'%s_users.json\'" % query)\n', (16087, 16134), False, 'import click\n'), ((16196, 16252), 'click.echo', 'click.echo', (['("File Created, name: \'%s_users.txt\'" % query)'], {}), '("File Created, name: \'%s_users.txt\'" % query)\n', (16206, 16252), False, 'import click\n'), ((2418, 2476), 'datetime.datetime.fromtimestamp', 'datetime.fromtimestamp', (["edge['node']['taken_at_timestamp']"], {}), "(edge['node']['taken_at_timestamp'])\n", (2440, 2476), False, 'from datetime import datetime\n'), ((10390, 10440), 'datetime.datetime.fromtimestamp', 'datetime.fromtimestamp', (["node['taken_at_timestamp']"], {}), "(node['taken_at_timestamp'])\n", (10412, 10440), False, 'from datetime import datetime\n')]