def do_it(s, hours): ids, cities = getIdsOfCities(s) while True: # getIdsOfCities is called on a loop because the amount of cities may change ids, cities_new = getIdsOfCities(s) if len(cities_new) != len(cities): cities = cities_new for cityId in cities: if 'reported' not in cities[cityId]: cities[cityId]['reported'] = False for cityId in cities: html = s.get(urlCiudad + cityId) city = getCity(html) # if the city doesn't even have a tavern built, ignore it if 'tavern' not in [ building['building'] for building in city['position'] ]: continue consumption_per_hour = city['consumo'] # is a wine city if cities[cityId]['tradegood'] == '1': wine_production = getProduccionPerSecond(s, cityId)[1] wine_production = wine_production * 60 * 60 if consumption_per_hour > wine_production: consumption_per_hour -= wine_production else: continue consumption_per_seg = Decimal(consumption_per_hour) / Decimal(3600) wine_available = city['recursos'][1] if consumption_per_seg == 0: if cities[cityId]['reported'] is False: msg = _('The city {} is not consuming wine!').format( city['name']) sendToBot(s, msg) cities[cityId]['reported'] = True continue seconds_left = Decimal(wine_available) / Decimal( consumption_per_seg) if seconds_left < hours * 60 * 60: if cities[cityId]['reported'] is False: time_left = daysHoursMinutes(seconds_left) msg = _('In {}, the wine will run out in {}').format( time_left, city['name']) sendToBot(s, msg) cities[cityId]['reported'] = True else: cities[cityId]['reported'] = False time.sleep(20 * 60)
def do_it(s): while True: (ids, cities) = getIdsOfCities(s) cityId = ids[0] url = 'action=AvatarAction&function=giveDailyActivityBonus&dailyActivityBonusCitySelect={0}&startPageShown=1&detectedDevice=1&autoLogin=on&cityId={0}&activeTab=multiTab2&backgroundView=city¤tCityId={0}&actionRequest=REQUESTID&ajax=1'.format( cityId) s.get(url) wait(24 * 60 * 60, 1 * 60 * 60)
def do_it(session): """ Parameters ---------- session : ikabot.web.session.Session """ while True: (ids, cities) = getIdsOfCities(session) cityId = ids[0] url = 'action=AvatarAction&function=giveDailyActivityBonus&dailyActivityBonusCitySelect={0}&startPageShown=1&detectedDevice=1&autoLogin=on&cityId={0}&activeTab=multiTab2&backgroundView=city¤tCityId={0}&actionRequest={1}&ajax=1'.format( cityId, actionRequest) session.post(url) wait(24 * 60 * 60, 1 * 60 * 60)
def getCommertialCities(s): ids = getIdsOfCities(s)[0] ciudades_comerciales = [] for idCiudad in ids: html = s.get(urlCiudad + idCiudad) ciudad = getCity(html) for pos, edificio in enumerate(ciudad['position']): if edificio['building'] == 'branchOffice': ciudad['pos'] = pos html = getStoreHtml(s, ciudad) rangos = re.findall(r'<option.*?>(\d+)</option>', html) ciudad['rango'] = int(rangos[-1]) ciudades_comerciales.append(ciudad) break return ciudades_comerciales
def do_it(session): """ Parameters ---------- session : ikabot.web.session.Session """ while True: (ids, cities) = getIdsOfCities(session) for id in ids: html = session.post(city_url + str(id)) if 'class="fountain' in html: url = 'action=AvatarAction&function=giveDailyActivityBonus&dailyActivityBonusCitySelect={0}&startPageShown=1&detectedDevice=1&autoLogin=on&cityId={0}&activeTab=multiTab2&backgroundView=city¤tCityId={0}&actionRequest={1}&ajax=1'.format( id, actionRequest) session.post(url) if 'class="fountain_active' in html: url = 'action=AmbrosiaFountainActions&function=collect&backgroundView=city¤tCityId={0}&templateView=ambrosiaFountain&actionRequest={1}&ajax=1'.format( id, actionRequest) session.post(url) break wait(24 * 60 * 60, 60)
def getCommercialCities(session): """ Parameters ---------- session : ikabot.web.session.Session Returns ------- commercial_cities : list[dict] """ cities_ids = getIdsOfCities(session)[0] commercial_cities = [] for city_id in cities_ids: html = session.get(city_url + city_id) city = getCity(html) for pos, building in enumerate(city['position']): if building['building'] == 'branchOffice': city['pos'] = pos html = getMarketHtml(session, city) positions = re.findall(r'<option.*?>(\d+)</option>', html) city['rango'] = int(positions[-1]) commercial_cities.append(city) break return commercial_cities
def do_it(session, hours): """ Parameters ---------- session : ikabot.web.session.Session hours : int """ was_alerted = {} while True: # getIdsOfCities is called on a loop because the amount of cities may change ids, cities = getIdsOfCities(session) for cityId in cities: if cityId not in was_alerted: was_alerted[cityId] = False for cityId in cities: html = session.get(city_url + cityId) city = getCity(html) # if the city doesn't even have a tavern built, ignore it if 'tavern' not in [ building['building'] for building in city['position'] ]: continue consumption_per_hour = city['consumo'] # is a wine city if cities[cityId]['tradegood'] == '1': wine_production = getProductionPerSecond(session, cityId)[1] wine_production = wine_production * 60 * 60 if consumption_per_hour > wine_production: consumption_per_hour -= wine_production else: was_alerted[cityId] = False continue consumption_per_seg = Decimal(consumption_per_hour) / Decimal(3600) wine_available = city['recursos'][1] if consumption_per_seg == 0: if was_alerted[cityId] is False: msg = _('The city {} is not consuming wine!').format( city['name']) sendToBot(session, msg) was_alerted[cityId] = True continue seconds_left = Decimal(wine_available) / Decimal( consumption_per_seg) if seconds_left < hours * 60 * 60: if was_alerted[cityId] is False: time_left = daysHoursMinutes(seconds_left) msg = _('In {}, the wine will run out in {}').format( time_left, city['name']) sendToBot(session, msg) was_alerted[cityId] = True else: was_alerted[cityId] = False time.sleep(20 * 60)