def create_app(): """ Creates and stores new App""" body = json.loads(request.data) unix_time = int(time.time()) new_app = App(name=body['name'], icon=body['icon'], createdAt=unix_time, updatedAt=unix_time) db.session.add(new_app) db.session.commit() return json.dumps({'success': True, 'data': new_app.serialize()}), 201
class UX(): bible = Bible() cxn = App() def __init__(self): pass def welcome(self): print("Welcome to the Terminal Bible App!") print("==================================\n") def readVerses(self): book = input("Please select the book you want to read from: ") chapter = input("Please select the chapter you want to read from: ") verse = input("Please select the verse you want to start from: ") book = self.bible.getBook(book) verse = "{chapter}.{verse}".format(chapter=chapter, verse=str(verse).zfill(3)) passage = self.bible.getPassage(book, verse) self.cxn.logger(book, verse) print("\n") for v in passage: print(v) print("\n") def bookmarkVerses(self): self.cxn.bookmark() def viewBookmarkedVerses(self): verses = self.cxn.getBookmarked() for verse in verses: print(verse) def search(self): query = input("Enter search keyword: ") result = self.bible.finder(query) for rec in result['ando']: print(rec) for rec in result['oro']: print(rec) def printHelp(self): apphelp = ''' Available options: ================== q - to quit b - to bookmark the last verse read v - to view bookmarked verses h - to repeat this message s - to search the bible r - to read verse ''' print(apphelp)
def assign_apps_to_announcement(announcement, apps): announcement.included_apps = [] for app in apps: app_model = get_app_by_name(app) if not app_model: app_model = App(name=app) db.session.add(app_model) announcement.included_apps += [app_model]
def getSVNLog(brand, app): try : app = App.get(App.brand == brand, App.name == app) if app: return SVNHelper.getSVNLogByApp(app) else: raise Exception("None Object App") except Exception as e: logging.debug(e) raise Exception("getSVNLog: " + str(e))
def infoApp(brand, app): try : app = App.get(App.brand == brand, App.name == app) servers = Server.raw( '''select * from t_server where id in ({0})'''.format(app.getConfig("SERVERS")) ) deploy = appmodule.createAppDeploy(app, [s for s in servers]) if deploy: app_status = deploy.getAppStatus() if len(app_status.keys()) > 0: return app_status else: return None else: raise Exception("None Object appdeploy") except Exception as e: logging.debug(e) raise Exception("infoApp: " + str(e))
def persist_app_data(session, app_data): apps = session.query(App).filter(App.bundle_id == app_data['appId']).all() if len(apps) < 1: a = App( title=app_data['title'], bundle_id=app_data['appId'], url=app_data['url'], developer=app_data['developer'], genre=app_data['genre'], content_rating=app_data['contentRating'], content_rating_description=app_data['contentRatingDescription'], contains_ads=app_data['containsAds'], installs=app_data['installs'], privacy_policy=app_data['privacyPolicy']) session.add(a) session.commit() session.refresh(a) return a.id return -1
def deployApp(brand, app, master_rev, config_rev): try : app_instance = App.get(App.brand == brand, App.name == app) app_instance.master_rev = master_rev app_instance.config_rev = config_rev servers = Server.raw( '''select * from t_server where id in ({0})'''.format(app_instance.getConfig("SERVERS")) ) # if prd: # profile = DBHelper().getProfile("prd") # else: # profile = DBHelper().getProfile("dev") deploy_instance = appmodule.createAppDeploy(app_instance, [s for s in servers]) if deploy_instance: deploy_instance.deploy() deploy_instance.saveHistory() return None else: raise Exception("None Object AppDeploy") except Exception as e: logging.debug(e) raise Exception("app deploy fail:" + str(e))
def checkServers(brand, app): try : app = App.get(App.brand == brand, App.name == app) servers = Server.raw( '''select * from t_server where id in ({0})'''.format(app.getConfig("SERVERS")) ) check_list = [] for server in servers: th = utils.CheckThread(server.host, server.port) check_list.append(th) th.start() for th in check_list: th.join() time.sleep(2) flag = True for th in check_list: flag = flag and th.retcode return flag except Exception as e: logging.debug(e) logging.debug("server not exist, check server fails:" + str(e)) return False
def _get_page_apps(p=1): _apps = [] _rbs = _get_html(url=_apk_page_url(p)) # _links 里是当页的所有 APP 的 a 标签 _links = _rbs.select('div.app_left_list > a') print('第', end=' ') for _i, _link in enumerate(_links): # 图片 _img = str(_link.select_one('img.alllist_img')['src']) _get_img(url=_img, name=((_i + 1) + ((p - 1) * 10))) # 链接 _url = _base_url + _link['href'] _app_info = get_app_info(_url) # 至于为什么在这里获取这几个数据是因为app详情页里有很多歧义数据,会使爬虫解析出现错误 # 名称 _name = str(_link.select_one('p.list_app_title').text).strip() # 点评 _review = str(_link.select_one('p.list_app_description').text).strip() # 将 App 对象添加到列表中,方便 orm 一次性提交 _apps.append( App(name=_name, url=_url, version=_app_info['version'], size=_app_info['size'], download=_app_info['download'], hot=_app_info['hot'], comment=_app_info['comment'], lang=_app_info['lang'], rank=_app_info['rank'], rank_num=_app_info['rank_num'], pkg_name=_app_info['pkg_name'], update=_app_info['update'], rom=_app_info['rom'], author=_app_info['author'], review=_review)) print('张图片保存成功') return _apps
def initialize_empty(): """ Initializes the database with 4 apps, each with a root test Return: List of the 4 App objects and a List of 4 Test objects """ curTime = int(time.time()) eatery = App( name='Eatery', icon= 'https://raw.githubusercontent.com/cuappdev/assets/master/app-icons/Eatery-83.5x83.5%402x.png', createdAt=curTime, updatedAt=curTime) db.session.add(eatery) eatery_test1 = Test(name='Campus Eateries Test', url='https://eatery-backend.cornellappdev.com/', method=MethodType('GET'), parameters='query{eateries{name}}', is_graphql=True, results=[], app_id=1, createdAt=curTime, updatedAt=curTime) eatery_test2 = Test(name='CTown Eateries Test', url='https://eatery-backend.cornellappdev.com/', method=MethodType('GET'), parameters='query{collegetownEateries{name}}', is_graphql=True, results=[], app_id=1, createdAt=curTime, updatedAt=curTime) db.session.add(eatery_test1) db.session.add(eatery_test2) curTime = int(time.time()) uplift = App( name='Uplift', icon= 'https://raw.githubusercontent.com/cuappdev/assets/master/app-icons/Uplift-83.5x83.5%402x.png', createdAt=curTime, updatedAt=curTime) db.session.add(uplift) uplift_test1 = Test(name='Campus Gyms Test', url='http://uplift-backend.cornellappdev.com/', method=MethodType('GET'), parameters='query{gyms{description}}', is_graphql=True, results=[], app_id=2, createdAt=curTime, updatedAt=curTime) uplift_test2 = Test(name='Gym Classes Test', url='http://uplift-backend.cornellappdev.com/', method=MethodType('GET'), parameters='query{classes{id}}', is_graphql=True, results=[], app_id=2, createdAt=curTime, updatedAt=curTime) db.session.add(uplift_test1) db.session.add(uplift_test2) curTime = int(time.time()) transit = App( name='Transit', icon= 'https://raw.githubusercontent.com/cuappdev/assets/master/app-icons/Transit-83.5x83.5%402x.png', createdAt=curTime, updatedAt=curTime) db.session.add(transit) transit_test = Test(name='Node Microservice Test', url='http://transit-backend.cornellappdev.com/api/v1/', method=MethodType('GET'), parameters='', results=[], app_id=3, createdAt=curTime, updatedAt=curTime) db.session.add(transit_test) curTime = int(time.time()) pollo = App( name='Pollo', icon= 'https://raw.githubusercontent.com/cuappdev/assets/master/app-icons/pollo-1024%401x.png', createdAt=curTime, updatedAt=curTime) db.session.add(pollo) pollo_test = Test(name='Root Test', url='http://transit-backend.cornellappdev.com/api/v1/', method=MethodType('GET'), parameters='', results=[], app_id=4, createdAt=curTime, updatedAt=curTime) db.session.add(pollo_test) db.session.commit()
from db import Bible, App from ui import UX ux = UX() # bible = Bible() # passage = bible.reader.execute("SELECT * FROM verses LIMIT 10") cxn = App() def app(): # for verse in passage: # print(verse) ux.welcome() while True: action = input(": ") if action == "q": break elif action == 's': ux.search() elif action == 'r': ux.readVerses() elif action == 'v': ux.viewBookmarkedVerses() elif action == 'b': ux.bookmarkVerses() elif action == "h": ux.printHelp() else: