def delete_torrent(): if not request.json or not request.json['torrent_id']: return { 'error': 'Request JSON not correct', 'code': 10, } torrent_id = request.json['torrent_id'] data = {'torrent_id': torrent_id, 'remove_data': True} with DelugeRPCClient(DELUGE_ADDR, int(DELUGE_PORT), DELUGE_USER, DELUGE_PASS) as client: # result = client.call('core.remove_torrent', data) result = client.core.remove_torrent(torrent_id, True) if result: return { 'torrent_id': torrent_id, 'success': 'success', 'code': 0, } else: return { 'torrent_id': torrent_id, 'error': 'Error deleting the torrent', 'code': 11, 'result': result } app.install(CorsPlugin(origins=['*'])) if __name__ == '__main__': run(app, host='localhost', port=8080)
#db_tasks.change_task(uid, **bottle.request.json) db_tasks.change_task(**bottle.request.json) #print(bottle.request.json) return "OK" # elif bottle.request.method == "OPTIONS": # db_tasks.change_task(bottle.request.json['uid'], **bottle.request.json) # print(bottle.request.json) # return "OK" @app.route("/api/delete/<uid:int>") def api_delete(uid): tasks_db.pop(uid) return "Ok" @app.route("/api/complete/<uid:int>") def api_complete(uid): tasks_db[uid].is_completed = True return "Ok" app.install(CorsPlugin(origins=['http://94.103.94.54:8080'])) #-------------------------------------------------------------------------- if __name__ == "__main__": bottle.run( app=app, host=app.config.host, port=app.config.port, server=app.config.server, )
if "is_completed" in bottle.request.json: print(bottle.request.json['is_completed']) tasks_db[uid].is_completed = bottle.request.json['is_completed'] else: tasks_db[uid].is_completed = False return f"Modified task {uid}" elif bottle.request.method == "DELETE": tasks_db.pop(uid) return f"Deleted task {uid}" """ @enable_cors @app.route("/api/delete/<uid:int>") def api_delete(uid): tasks_db.pop(uid) return "Ok" @enable_cors @app.route("/api/complete/<uid:int>") def api_complete(uid): tasks_db[uid].is_completed = True return "Ok" """ app.install(CorsPlugin(origins=['http://localhost:8080'])) ### if __name__ == "__main__": bottle.run(app, host="localhost", port=5000)
max_uid = max(tasks_db.keys()) else: max_uid = 0 new_uid = max_uid + 1 t = TodoItem(desc, new_uid) t.is_completed = is_completed t.priority = priority tasks_db[new_uid] = t return 'OK' @enable_cors @app.route('/api/tasks/<uid:int>', method=['GET', 'PUT', 'DELETE']) def show_or_modify_task(uid): if bottle.request.method == 'GET': return tasks_db[uid].to_dict() elif bottle.request.method == 'PUT': if 'description' in bottle.request.json: tasks_db[uid].description = bottle.request.json['description'] if 'priority' in bottle.request.json: tasks_db[uid].priority = bottle.request.json['priority'] tasks_db[uid].is_completed = 'is_completed' in bottle.request.json # q.d() return f"Modified task {uid}" elif bottle.request.method == 'DELETE': tasks_db.pop(uid) return f"Deleted task {uid}" app.install(CorsPlugin(origins=['http://127.0.0.1:5000'])) bottle.run(app, host='127.0.0.1', port=5000)
def post_comment(): comment = request.json.get('comment') email = request.json.get('email') payload = { 'eventData': { 'eventType': 'Comment', } } if comment: payload['eventData']['comment'] = comment if email: payload['eventData']['email'] = email res = requests.post( 'https://api.kevalin.io/v0/collections/SERVICE.R4R.COMMENTS/events', headers={'Authorization': f'X-API-Key {os.getenv("KEVALIN_API_KEY")}'}, json=payload) res.raise_for_status() # Static files route @app.get('/<filename:path>') def get_static_files(filename): """Get Static files""" return static_file(filename, root=STATIC_DIR) app.install(CorsPlugin(origins=['*.rax.io'])) # Run server run(app, server='auto', host='0.0.0.0', port=8080, reloader=True)
response.content_type = 'application/json' p = Params() p.setPercentCrossover(Genetic.PercentCrossover) p.setPercentMutation(Genetic.PercentMutation) p.setMaxPopulation(Genetic.MaxPopulation) p.setMaxGenerations(Genetic.MaxGenerations) p.setCrossoverPoints(Genetic.CrossoverPoints) p.setMaxMutation(Genetic.MaxMutation) p.setNumberSelection(Genetic.NumberSelection) p.setWalkPoint(Genetic.WalkPoint) p.setWallPoint(Genetic.WallPoint) p.setOffPoint(Genetic.OffPoint) p.setGoalPoint(Genetic.GoalPoint) return json.dumps(p.__dict__) elif request.method == 'POST': Genetic.PercentCrossover = float(request.json['percentCrossover']) Genetic.PercentMutation = float(request.json['percentMutation']) Genetic.MaxPopulation = int(request.json['maxPopulation']) Genetic.MaxGenerations = int(request.json['maxGenerations']) Genetic.CrossoverPoints = int(request.json['crossoverPoints']) Genetic.MaxMutation = int(request.json['maxMutation']) Genetic.NumberSelection = int(request.json['numberSelection']) Genetic.GoalPoint = int(request.json['goalPoint']) Genetic.WalkPoint = int(request.json['walkPoint']) Genetic.OffPoint = int(request.json['offPoint']) Genetic.WallPoint = int(request.json['wallPoint']) app.install(CorsPlugin()) run(app)
'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'] return {'day': dt.now().day, 'month': month[dt.now().month], 'year': dt.now().year} @app.route("/about") @view('about') def about(): return {'test': 3} @app.route('/static/<filename>') def send_css(filename): return static_file(filename, root='static') app.install(CorsPlugin(origins=['https://enz0g.github.io'])) if os.environ.get('APP_LOCATION') == 'heroku': run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 5000))) else: run(app, host='localhost', port=8080)
try: if bottle.request.method == 'DELETE': db.delete_task(session, uid) return 'The task is deleted successfully' elif bottle.request.method == 'PUT': db.make_task_completed(session, uid) return 'The task is completed successfully' except IndexError: return bottle.HTTPError(404, f'No task with uid {uid}') @enable_cors @app.route('/api/add-task', method='POST') def add_task(): description = bottle.request.json['description'].strip() if len(description) > 0: db.add_task(session, description) return 'The task is added successfully' app.install(CorsPlugin(origins=os.environ.get('CORS_URLS'))) if os.environ.get('APP_LOCATION') == 'heroku': bottle.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 5000))) else: bottle.run(app, host='localhost', port=5000)