Esempio n. 1
0
def data_loading(request, content_type, htmlname):
    params = content_type_dict[content_type].copy()
    repo = params["repo"]
    query = params["query"].format(htmlname)
    params.update({"htmlname": htmlname})
    if not Github.has_already_created(repo, htmlname):
        tweet_list = []
        myTwitterAction = Twitter.MyTwitterAction()
        if content_type == "legends":
            tweet_list = myTwitterAction.search_tweet_list_universal(query,
                                                                     amount=50)
        elif content_type == "overseas":
            tweet_list = myTwitterAction.search_tweet_list(query, amount=50)
            try:
                tweet_list = translate_tweet_list(tweet_list)
            except:
                pass
        else:
            tweet_list = myTwitterAction.search_tweet_list(query, amount=50)

        git_json = {}
        git_json.update({"tweet_list": tweet_list})
        text = json.dumps(git_json, ensure_ascii=False, indent=4)
        Github.upload(repo, htmlname, text)
    return render(request, f"ranking/ranking.html", params)
Esempio n. 2
0
def main():
    tag_list = Github.seach_page_list(repo)
    for htmlname in tag_list:
        Github.delete_page(repo, htmlname)
        print("mainloop:", htmlname, "has deleted")
        myTwitterAction = Twitter.MyTwitterAction()
        tweet_list = myTwitterAction.search_tweet_list(
            '"' + htmlname + '"' + " lang:ja min_faves:100", amount=50)

        git_json = {}
        git_json.update({"tweet_list": tweet_list})

        text = json.dumps(git_json, ensure_ascii=False, indent=4)
        Github.upload(repo, htmlname, text)
        print("mainloop:", htmlname, "is created")
        time.sleep(4)
Esempio n. 3
0
def main2():
    repo = "overseas"
    for htmlname in Github.seach_page_list(repo):

        tweet_list = []
        myTwitterAction = Twitter.MyTwitterAction()
        query = htmlname + " lang:en min_faves:100"
        tweet_list = myTwitterAction.search_tweet_list(query, amount=50)
        tweet_list = translate_tweet_list(tweet_list)

        git_json = {}
        git_json.update({"tweet_list": tweet_list})
        text = json.dumps(git_json, ensure_ascii=False, indent=4)
        Github.delete_page(repo, htmlname)
        Github.upload(repo, htmlname, text)
        time.sleep(4)
Esempio n. 4
0
def data_loading(request, htmlname):
    result = seach(request)
    if result:
        return result
    params = {
        "title": "twitterアカウント分析サイト",
        "description": site_explain,
        "favicon": favicon,
        "img": img,
        "repo": repo,
        "htmlname": htmlname,
    }
    if not Github.has_already_created(repo, htmlname):
        myTwitterAction = Twitter.MyTwitterAction()
        tweet_list = myTwitterAction.search_tweet_list(htmlname, amount=50)

        git_json = {}
        git_json.update({"tweet_list": tweet_list})

        git_json.update({"wordcloud": genWordList(tweet_list)})

        text = json.dumps(git_json, ensure_ascii=False, indent=4)
        Github.upload("twitter_json", htmlname, text)
    return render(request, f"fanstatic/dashboard/dashboard.html", params)
Esempio n. 5
0
def create_network_json(root_name):
    root_name = "@" + root_name.replace("@", "")
    link_list = []
    acount_list = []
    acount_set = set()

    myTwitterAction = Twitter.MyTwitterAction()

    def induction_json(parent_name, depth, node_num):
        if depth < 0:
            return
        tweet_list = myTwitterAction.search_tweet_list(parent_name, amount=100)
        dub_tweet_list, non_dub_tweet_list = get_dub_acount(
            tweet_list, acount_set)

        for tweet in dub_tweet_list:
            acount_name = "@" + tweet["user"]["screen_name"]
            if acount_name in acount_set:
                pass
            else:
                acount_set.add(acount_name)
                acount_list.append(grep_node_info(tweet))
            link_list.append({
                "target": acount_name,
                "source": parent_name,
                "value": 1
            })
            induction_json(acount_name, depth - 1, int(node_num / 2))

        for tweet in non_dub_tweet_list[:max(0, node_num -
                                             len(dub_tweet_list))]:
            acount_name = "@" + tweet["user"]["screen_name"]
            if acount_name in acount_set:
                pass
            else:
                acount_set.add(acount_name)
                acount_list.append(grep_node_info(tweet))
            link_list.append({
                "target": acount_name,
                "source": parent_name,
                "value": 1
            })
            induction_json(acount_name, depth - 1, int(node_num / 2))

    def grep_node_info(tweet):
        base = {
            "name": "@" + tweet["user"]["screen_name"],
            "img": tweet["user"]["profile_image_url"],
            "text": tweet["text"],
            "group": 1
        }
        return base

    def get_dub_acount(tweet_list, acount_set):
        dub_tweet_list = []
        non_dub_tweet_list = []
        for tweet in tweet_list:
            acount_name = "@" + tweet["user"]["screen_name"]
            if acount_name in acount_set:
                dub_tweet_list.append(tweet)
            else:
                non_dub_tweet_list.append(tweet)
        return dub_tweet_list, non_dub_tweet_list

    induction_json(root_name, 1, 50)
    if root_name not in acount_set:
        acount_list.append({
            "name": root_name,
            "img":
            "https://cdn.icon-icons.com/icons2/1144/PNG/512/twitterlogo1_80940.png",
            "text": "本人",
            "group": 1
        })
    return {"nodes": acount_list, "links": link_list}