Пример #1
0
 def GET(self, name):
     d = db.get_candidate(name)
     if d is None:
         raise web.seeother('/search?' +
                            urllib.urlencode(dict(
                                q=name.replace('_', ' '))))
     return render.candidate(d)
Пример #2
0
def show_candidate(slug=None):
    """
    """
    if slug is None:
        return "Candidate not provided"

    candidate = db.get_candidate(slug)
    if candidate is None:
        return "Candidate not found"

    full_name = get_full_name(candidate['name'])

    twitter_user = db.getUser(candidate.get('twitter_handle'))
    twitter_data = None
    followers = {"numFollowers": None, "numBots": None, "numHumans": None}
    word_cluster = {'topics': []}
    if twitter_user:
        twitter_data = {"profile_url": twitter_user["twitter"]["profile_image_url_https"]}
        followers["numFollowers"] = twitter_user["twitter"]["followers_count"]
        follower_stats = db.getFollowerStats(candidate['twitter_handle'])
        followers.update(follower_stats)
        word_frequencies = twitter_user.get('word_frequencies')
        if word_frequencies:
            word_cluster = word_frequencies

    election = candidate['election']
    district = db.get_district(election['district'])
    election['district'] = {'id': district['_key'], 'name': district['name']}

    json_output = {
        "content": "MEMBER", 
        "member": {
            "name": full_name,
            "twitter_handle": candidate.get('twitter_handle'),
            "facts" : candidate["facts"],
            "links" : candidate["links"],
            "photos" : candidate["photos"]
        },
        "twitter": twitter_data,
        "wordCluster": word_cluster,
        "followers": followers,
        "retweets": {
              "numRetweets": None,
              "numHumans": None,
              "numBots": None
        },
        "retweeters": {
              "numRetweeters": None,
              "numHumans": None,
              "numBots": None
        },
        "election": election,
        "botness": twitter_user["botness"] if twitter_user and "botness" in twitter_user else {}
    }

    return jsonify(json_output)
Пример #3
0
def show_result():
    if request.method == "POST":
        manager = Manager()
        data = manager.get_result()
        address = data['_candidate']
        if hex(int(address, base=16)) == hex(0):
            message = 'No Candidate Won!!!'
        else:
            message = get_candidate(address) + 'Won !!!'

        return Response(json.dumps(message))
    else:
        return 403
Пример #4
0
def candidate_info(slug=None):
    """
    """
    if slug is None:
        return "Candidate not provided"

    candidate = db.get_candidate(slug)
    if candidate is None:
        return "Candidate not found"

    full_name = get_full_name(candidate['name'])

    twitter_user = db.getUser(candidate['twitter_handle'])
    if twitter_user is None:
        return "Twitter user for candidate lost in the dark forest - make a donation to us to find this user."

    followers = {"numFollowers": twitter_user["twitter"]["followers_count"]}
    follower_stats = db.getFollowerStats(candidate['twitter_handle'])
    followers.update(follower_stats)

    json_output = {
        "content": "MEMBER",
        "facts": candidate["facts"],
        "links": candidate["links"],
        "photos": candidate["photos"],
        "member": {
            "name": full_name,
            "pictureURL": '',
            "party": candidate["election"]["party"],
            "twitter_handle": candidate['twitter_handle']
        },
        "wordCluster": twitter_user.get("word_frequencies"),
        "followers": followers,
        "retweets": {
            "numRetweets": 12,
            "numHumans": 11,
            "numBots": 1
        },
        "retweeters": {
            "numRetweeters": 22,
            "numHumans": 9,
            "numBots": 13
        },
        "election": candidate['election'],
        "botness":
        twitter_user["botness"] if "botness" in twitter_user else {}
    }

    return jsonify(json_output)
Пример #5
0
 def GET_json(self, name):
     d = db.get_candidate(name)
     if d is None:
         raise web.notfound()
     return d
Пример #6
0
 def GET(self, name):
     d = db.get_candidate(name)
     if d is None:
         raise web.seeother('/search?' + urllib.urlencode(dict(q=name.replace('_', ' '))))
     return render.candidate(d)
Пример #7
0
    parser.add_argument('-b',
                        '--both',
                        action='store_true',
                        help='get both available entities')
    parser.add_argument('-a',
                        '--all',
                        action='store_true',
                        help='get all candidates')

    args = parser.parse_args()
    if not (args.tweets or args.followers or args.both):
        parser.error('No action requested, please see --help')

    if args.all:
        FOLLOWER_LIMIT = 0

    slugs_to_scan = db.get_all_candidate_slugs() if args.all else SLUGS
    for slug in slugs_to_scan:
        candidate = db.get_candidate(slug)
        if 'twitter_handle' not in candidate:
            print(candidate["slug"] + " is missing a twitter handle")
            continue
        twitter_handle = candidate['twitter_handle']
        if args.both:
            save_tweets_with_retweets(twitter_handle)
            save_followers_with_botness(twitter_handle)
        elif args.tweets:
            save_tweets_with_retweets(twitter_handle)
        elif args.followers:
            save_followers_with_botness(twitter_handle)
Пример #8
0
 def GET(self, name):
     d = db.get_candidate(name)
     return render.candidate(d)
Пример #9
0
 def GET_json(self, name):
     d = db.get_candidate(name)
     if d is None:
         raise web.notfound()
     return d