@sync_loop_call(60 * 1000)
@gen.coroutine
def update_world_location():
    options.logger.info("start update world_location")
    global world_location_map
    global world_map
    if not world_location_map:  # get file into world_location_map
        resp = yield GetPage(options.api_url + options.world_location_map_gist)
        if resp.code == 200:
            resp = escape.json_decode(resp.body)
            raw_url = resp["files"]["world_location_map.json"]['raw_url']
            resp = yield GetPage(raw_url)
            if resp.code == 200:
                world_location_map = escape.json_decode(resp.body)
            else:
                options.logger.error("Fetch raw data error %d, %s" %
                                     (resp.code, resp.message))
        else:
            options.logger.error("Get gist error %d, %s" %
                                 (resp.code, resp.message))

    else:  # update world_location_map file every hour
        if int(time.time()) % 36000 < 60:
            resp = yield update_file(options.api_url + options.world_location_map_gist,
                                     "world_location_map.json",
                                     world_location_map)
            if resp.code != 200:
                options.logger.error("update gists error %d, %s" %
                                    (resp.code, resp.message))

    temp_world_map = {}
    for country_code in options.country_code_list:
        temp_world_map[country_code] = {"score": 0, "staticInitColor": 6}

    for user in github_world:
        if not user["location"]:
            continue
        try:
            location = user["location"].strip()
            location = ','.join(filter(lambda d: d,
                                ','.join(location.split()).split(',')))
        except Exception, e:
            options.logger.error("Error: %s" % e)
            continue
        if location in world_location_map:
            country_code = world_location_map[location]
        else:
            country_code = yield match_world_geoname(location)
        if country_code:
            temp_world_map[country_code]["score"] += 1
            world_location_map[location] = country_code
        else:
            options.logger.warning("location: %s can't match" % location)

    world_map = temp_world_map.copy()
dataset/ETHPy150Open cloudaice/simple-data/github/workers.py/update_world_location/original