def update(config): """Load dumped items from yaml file and applies changes""" def color(obj): return '\033[92m' + str(obj) + '\033[0m' stored_items = load_dump(config.file) current_items = api.dump(config) changes = [] changed_items = [] for item in current_items: if int(item.ItemID) in stored_items: stored_item = stored_items[int(item.ItemID)] diff = {} stored = int(stored_item['quantity']) current = int(item.QuantityAvailable) if stored != current: item.QuantityAvailable = color('%s > %s' % (current, stored)) diff['Quantity'] = stored stored = stored_item['title'] current = item.Title if stored != current: diff['Title'] = stored item.QuantityAvailable = color('%s > %s' % (current, stored)) stored = stored_item['price'] current = float(item.BuyItNowPrice.value) if stored['value'] != current: diff['StartPrice'] = { '#text': stored['value'], '@attrs': { 'currencyID': stored['currency'] } } item.BuyItNowPrice.value = color('%s > %s' % (current, stored['value'])) if diff: diff['ItemID'] = item.ItemID changes.append({'Item': diff}) changed_items.append(item) if changes: print 'Changes:' print_items(changed_items) if raw_input('apply (y/N) ? ') == 'y': api.update(config, changes) else: LOG.info('Nothing has changed.')
def save(): entity = None data = json.loads(request.data)['entity'] if data['id']: entity = Entity.query.get(data['id']) elif data['name']: entity = Entity(data['name']) db.add(entity) db.commit() if entity: update(entity, data) cache.clear() else: print 'NO UPDATE' return get_entities()
def alarm(context: CallbackContext) -> None: """Send the alarm message.""" job = context.job new_price = update() if new_price < drop_price: context.bot.send_message( job.context, text=f'Price Dropped!! New Price: Rs{new_price}')
def update(lang=None, uuid=None, is_up=1, vote=None): response = api.update(lang, uuid, vote, is_up_vote=bool(int(is_up))) print ' >>>>>>>>>> ', bool(int(is_up)), is_up response = dict(next='show_vote',data=[{key:str(val) for key, val in response['Attributes'].items()}][0]) print '..............', response return flask.jsonify(response)
def sumbit_form(): #print(request.args) desired_low = request.args.get('desired_low') desired_high = request.args.get('desired_high') desired_notification_time = request.args.get('desired_notification_time') print("This is the type of desired_low") print(type(desired_low)) print('THIS IS THE TYPE OF DESIRED NOTIFICATION TIME') print(type(desired_notification_time)) api.update(desired_low, desired_high, desired_notification_time) #return render_template('update.html',set1='Updated Low', set2='Updated High', desired_low = desired_low, desired_high = desired_high) return login_dashboard()
def save(): app.logger.debug('SAVING') app.logger.debug(request.data) entity = None data = json.loads(request.data)['entity'] if data['id']: entity = Entity.query.get(data['id']) elif data['name']: app.logger.debug('ADDING NEW ENTITY ' + str(data['name'])) entity = Entity(str(data['name'])) db.add(entity) db.commit() if entity: app.logger.debug('UPDATING ENTITY ' + entity.name) update(entity, data) cache.clear() else: app.logger.debug('NO UPDATE') return get_entities()
def edit(): username = request.get_cookie("username", settings.cookie_secret) password = request.get_cookie("password", settings.cookie_secret) ok = api.check(username, password) if ok: username = username.lower() if request.method == "GET": meeting_id = request.params.get("meeting_id") info = api.get_meeting_info(meeting_id) if username not in info.get("moderator_users") and username not in settings.admins: redirect("/start") users = api.suggest("") # username = username.lower() # if username in users: # users.remove(username) attendee_users = info.get("attendee_users") if "" in info.get("attendee_users"): attendee_users.remove("") attendee_users = [x.strip() for x in attendee_users] # remove start/end space if username not in attendee_users: attendee_users.append(username) info["attendee_users"] = attendee_users users = [x for x in users if x not in attendee_users] return jinja2_template("edit.html", users=users, info=info) else: meeting_id = request.params.get("meeting_id") name = request.params.get("name") attendee_users = request.params.get("attendee_users").split(",") attendee_users = [x.strip() for x in attendee_users if x != ""] api.update(username, meeting_id, name, attendee_users) redirect("/start")
def run(): response_profile = crawl_profile() if response_profile.status_code != 200: print( f"{__file__}: Request failed with status code {response_profile.status_code}" ) return for key, value in parse_profile(response_profile.content).items(): if value is None: print(f"{__file__}: Parsing {key} failed") return update_response = api.update(key, value) if update_response.status_code != 200: print( f"{__file__}: Update of value {key} failed with status code {update_response.status_code}" ) return response_rank_page_count = crawl_rank_page_count() if response_rank_page_count.status_code != 200: print( f"{__file__}: Request failed with status code {response_rank_page_count.status_code}" ) return rank_page_count = parse_rank_page_count(response_rank_page_count.content) if rank_page_count == 0: print(f"rank_page_count was zero") return update_response = api.update("ac_total_user_count", rank_page_count * 100) if update_response.status_code != 200: print( f"{__file__}: Update failed with status code {update_response.status_code}" ) return print(f"{__file__}: Successfully updated")
def run(): response = crawl() if response.status_code == 200: for key, value in parse(response.content).items(): if value is None: print(f"{__file__}: Parsing {key} failed") return update_response = api.update(key, value) if update_response.status_code != 200: print(f"{__file__}: Update of value {key} failed with status code {update_response.status_code}") return else: print(f"{__file__}: Request failed with status code {response.status_code}") return print(f"{__file__}: Successfully updated")
def main(): """Shows basic usage of the Sheets API. Prints values from a sample spreadsheet. """ # The ID and range of a sample spreadsheet. spreadsheet_id = config['spreadsheet']['id'] service = api.service() conn = database.connection() cursor = conn.cursor() # Call the Sheets API spreadsheet = service.spreadsheets() for sheet in config['spreadsheet']['sheets']: query = config['spreadsheet']['sheets'][sheet]['query'] range = config['spreadsheet']['sheets'][sheet]['name'] + '!' + config[ 'spreadsheet']['sheets'][sheet]['range'] cursor.execute(query) cols = [desc[0] for desc in cursor.description] rows = cursor.fetchall() values = [cols] for row in rows: values.append(list(row)) update_range = range + str(len(values)) response_cleared = api.clear(spreadsheet=spreadsheet, id=spreadsheet_id, range=range) body = {'range': update_range, 'values': values} response_update = api.update(spreadsheet=spreadsheet, id=spreadsheet_id, range=update_range, body=body) if conn is not None: conn.close()
#!/usr/bin/env python import api import json payload = json.dumps({"running": True}) api.update(payload)
def updateBook(): api.update(selectedBook[0], titleText.get(), authorText.get(), yearText.get(), isbnText.get()) viewBooks()