def crawlEastMoney(): db.initDb() etfListUrl="http://fund.eastmoney.com/ETFN_jzzzl.html" eftHistUrl="http://api.fund.eastmoney.com/f10/lsjz?callback={0}&fundCode={1}&pageIndex=1&pageSize={3}&startDate=&endDate=&_={2}" callback='jQuery18303575276080195784_1602819402553' crawler=Crawler(**{'referer':'http://fundf10.eastmoney.com/'}) # 获取etf列表 html=crawler.downloadHtml(etfListUrl) items=cleaner.getEtfList(html) db.insertList(items) # 插入etf历史净值 db.clear('fund_hist') for item in items: code=item['code'] print(code) ts=int(time.time()) # 获取历史净值记录条数 url=eftHistUrl.format(callback,code,ts,1) content=crawler.downloadHtml(url) size=cleaner.getHistCount(content,callback) # 一次性获取所有历史净值 url=eftHistUrl.format(callback,code,ts,size) content=crawler.downloadHtml(url) items=cleaner.getHistList(content,callback,code) db.insertHistList(items)
def POST(self): form = config_form() result = db.getOAuthConnectionDetails(db.getConn(core.configobj)) token = result[0] secret = result[1] smugmug.set_oauth_token(token, secret) if not form.validates(): return self._GET(smugmug, form, False, form.value['root_dir'],form.value['log_dir'],form.value['data_dir'],form.value['start_time_hour']+':'+form.value['start_time_minute']) else: try: if smugmug.oauth_token == None: smugmug.auth_getAccessToken() except smugpy.SmugMugException: return self._GET(smugmug, form, True, form.value['root_dir'],form.value['log_dir'],form.value['data_dir'],form.value['start_time_hour']+':'+form.value['start_time_minute']) else: #self.first = False core.configobj.picture_root = form.value['root_dir'] core.configobj.log_dir = form.value['log_dir'] core.configobj.data_dir = form.value['data_dir'] core.configobj.start_time = form.value['start_time_hour']+':'+form.value['start_time_minute'] core.configobj.saveConfig() myLogger.info("Config file Created.") db.initDb(core.configobj) myLogger.info("Database started.") db.setOAuthConnectionDetails(db.getConn(core.configobj), smugmug.oauth_token, smugmug.oauth_token_secret) return self._GET(smugmug, form, False, core.configobj.picture_root, core.configobj.log_dir, core.configobj.data_dir,core.configobj.start_time)
def main(): from __init__ import Base from db import initDb dbconfig = dict(db_uri = "sqlite://") initDb(dbconfig, base=Base) initlinks(Base) print("foreign_keys:") for key, value in foreign_keys.items(): print(key, value) print("foreign_keys_c:") for key, value in foreign_keys_c.items(): print(key, value)
def POST(self): form = setup_form() if not form.validates(): return self._GET(form, False) else: try: smugmug.auth_getAccessToken() except smugpy.SmugMugException: return self._GET(form, True) else: #self.first = False core.configobj.picture_root = form.value['root_dir'] core.configobj.log_dir = form.value['log_dir'] core.configobj.data_dir = form.value['data_dir'] core.configobj.saveConfig() myLogger.info("Config file Created.") db.initDb(core.configobj) myLogger.info("Database started.") db.setOAuthConnectionDetails(db.getConn(core.configobj), smugmug.oauth_token, smugmug.oauth_token_secret) return web.seeother('/')
from flask import Flask from flask_bcrypt import Bcrypt from flask_cors import CORS from flask_jwt_extended import JWTManager from flask_restful import Api from db import initDb from routes.routes import initRoutes application = Flask(__name__) CORS(application) application.config["JWT_SECRET_KEY"] = environ["FLASK_JWT_SECRET"] application.config["MONGODB_SETTINGS"] = { "host": f"mongodb://{environ['MONGO_USERNAME']}:{environ['MONGO_PASSWORD']}@{environ['MONGO_HOST']}:{environ['MONGO_PORT']}/{environ['MONGO_DBNAME']}" } api = Api(application) bcrypt = Bcrypt(application) jwt = JWTManager(application) initDb(application) initRoutes(api) if __name__ == "__main__": ENVIRONMENT_DEBUG = environ.get("FLASK_ENV", "production") == "development" ENVIRONMENT_PORT = environ.get("FLASK_PORT", 4242) application.run("0.0.0.0", ENVIRONMENT_PORT, ENVIRONMENT_DEBUG)
import pytest import db db.initDb("med_img_test") in_dict1 = {"name": "test_img1.jpeg", "b64str": "/9j/4AAQSkZJRgABAgAA", "imgsize": "120X123", "processed": False, "timestamp": "2020-05-07"} in_dict2 = {"name": "test_img2.png", "b64str": "/9j/4AAQSkZJRgABAgAA", "imgsize": "280X322", "processed": True, "timestamp": "2020-05-02"} in_dict3 = {"name": "test_img3.jpg", "b64str": "/9j/4AAQSkZJRgABAgAA", "imgsize": "194X322", "processed": False, "timestamp": "2020-05-02"} img_name1 = "test_img1.jpeg" img_name2 = "test_img2.png" img_name3 = "test_img3.jpg" @pytest.mark.parametrize("in_dict", [ (in_dict1), (in_dict2),
import time from hmcException import * urls = ( '/admin', 'admin.admin_app', '/data', 'data.data_app', '/store', 'store.store_app', ) # 多线程的函数,用来启动 watchdog,监控目录中的文件变化 def watch(): mm = main() print mm.songStroageDir mm.start() if __name__ == '__main__': try: db.initDb() except CreateTableError: print "myslq operate has exception" thread.start_new_thread(watch, ()) app = web.application() app.run()
def verifyInfo(in_dict, sample_dict): """Verify whether the input dictionary is valid. An input dictionary is valid when 1) all the keys in the sample dictionary can be found in the input dictionary; 2) values in the input dictionary should have the same datatype as what in the smaple dictionary Args: in_dict (dict): An input dictionary. sample_dict (dict): An sample dictionary. Returns: (tuple): tuple containing: bool: True if the input dictionary is valid else False. str: Detialed message about the checking status. """ for key, ddtype in sample_dict.items(): if key not in in_dict: msg = "{} key not found".format(key) return False, msg if type(in_dict[key]) is not ddtype: msg = "{} value not correct type".format(key) return False, msg return True, "" if __name__ == "__main__": log_fpath = "develop.log" logging.basicConfig(filename=log_fpath, level=logging.INFO) db.initDb("medicalimage") app.run()