Beispiel #1
0
    def getUncompletedList(self):
        #util.get_today()
		
        params = {
            "CSRF": self.CSRF,
            "StartTime": util.get_today()+" 18:00",
            "EndTime": util.get_today()+" 21:00"
        }
        return self.request("https://api.uyiban.com/officeTask/client/index/uncompletedList", params=params,
                            cookies=self.COOKIES)
Beispiel #2
0
def mark():
    uid = request.args.get('uid')
    r0 = db.execute_query(
        "select cur_date from calendar where uid=? and cur_date=?",
        (uid, util.get_today()))
    if len(r0) != 0:
        return {'status': 404, 'msg': '已签过到'}
    res = db.execute("insert into calendar values (?,?)",
                     (uid, util.get_today()))
    res0 = db.execute_query("select cur_date from calendar where uid=?",
                            (uid, ))
    res0 = [i['cur_date'] for i in res0]
    return {'status': 200, 'msg': '签到成功', 'data': res0}
Beispiel #3
0
def get_schedule():
    uid = request.args.get('uid')
    res = db.execute_query("select * from schedule where uid=?", (uid, ))
    print(uid, res)
    if len(res) == 0:
        return {'status': 404, 'msg': '未添加计划'}
    res1 = db.execute_query("select num from book where book_id=?",
                            (res[0]['book_id'], ))

    res[0]['num'] = res1[0]['num']

    global time_start
    if time_start is None:
        time_start = datetime.datetime.now()
    time_end = datetime.datetime.now()
    duration = (time_end - time_start).seconds / 60
    r0 = db.execute("update record set time_day=?", (duration, ))
    print(duration)
    res0 = db.execute_query("select * from record where uid=? and cur_date=?",
                            (uid, util.get_today()))
    if len(res0) == 0:
        res[0]['learn_day'] = 0
        res[0]['review_day'] = 0
        res[0]['time_day'] = 0
    else:
        res[0]['learn_day'] = res0[0]['learn_day']
        res[0]['review_day'] = res0[0]['review_day']
        res[0]['time_day'] = res0[0]['time_day']
    return {'status': 200, 'data': res[0]}
Beispiel #4
0
def download_latest():
    if not util.is_trade_day(): return

    latest_day = util.get_today()
    re_download = True

    pagesize = 88
    stocks = load_all_stocks()
    count = len(stocks)
    params = [s[0] for s in stocks]
    pagecount = int(math.ceil(count / pagesize))

    dir_today = '%s%s/' % (config.daily_data_dir, latest_day)

    print "download 下载文件"
    for i in range(0, pagecount + 1):
        print i
        url = const_base_url + ','.join(
            params[i * pagesize:(i + 1) * pagesize])
        lfile = '%s%s.csv' % (dir_today, i)
        if re_download:
            if not os.path.exists(dir_today):
                os.mkdir(dir_today)
            if os.path.exists(lfile):
                os.remove(lfile)
            try:
                browser.downad_and_save(url, lfile)
            except Exception, e:
                print str(e)
Beispiel #5
0
def get_file_name():
    today = util.get_today()
    if not os.path.exists(today):
        os.mkdir(today)
    filename = today + os.sep + util.get_now_str() + "_163_top.txt"
    print filename
    return filename
Beispiel #6
0
def get_file_name():
    today = util.get_today()
    if not os.path.exists(today):
        os.mkdir(today)
    filename = today + os.sep + util.get_now_str() + "_163_top.txt"
    print filename
    return filename
Beispiel #7
0
def download_latest():
    if not util.is_trade_day(): return 

    latest_day = util.get_today()
    re_download = True

    pagesize = 88
    stocks = load_all_stocks()
    count = len(stocks)
    params = [s[0] for s in stocks]     
    pagecount = int(math.ceil(count/pagesize)) 
    
    dir_today = '%s%s/' %(config.daily_data_dir,latest_day)   

    print "download 下载文件"    
    for i in range(0,pagecount+1):
        print i
        url = const_base_url + ','.join(params[i*pagesize:(i+1)*pagesize])        
        lfile = '%s%s.csv' %(dir_today,i)
        if re_download:
            if not os.path.exists(dir_today):
                os.mkdir(dir_today) 
            if os.path.exists(lfile):
                os.remove(lfile) 
            try:
                browser.downad_and_save(url,lfile)
            except Exception,e:
                print str(e)
 def cb(msg):
     po = msgpack.unpackb(msg.payload_objects[0].content)
     if not isinstance(po, dict): return
     client_id = msg.uri.split('/')[2]
     start = po.get('predstart')
     start = parse(start) if start else get_today()
     end = po.get('predend')
     end = parse(end) if end else get_today() + datetime.timedelta(
         days=1)
     resolution = po.get('resolution', '1h')
     result = prediction_fxn(start, end, resolution)
     po = PayloadObject((2, 0, 0, 0), None, msgpack.packb(result))
     publish = '{0}/s.predictions/{1}/i.{2}/signal/response'.format(
         namespace, client_id, prediction_type)
     print "Respond on", publish
     c.publish(publish, payload_objects=(po, ))
Beispiel #9
0
def set_schedule():
    uid = request.args.get('uid')
    user = db.execute_query("select * from user where uid=?", (uid, ))
    if len(user) == 0:
        return {'status': 404, 'msg': '用户不存在'}
    book_id = request.args.get('book_id')
    num_daily = request.args.get('num_daily')
    query = db.execute_query("select * from schedule where uid=?", (uid, ))
    if len(query) != 0:
        res = db.execute(
            "update schedule set book_id=?, start_date=?, num_daily=?, current_progress=1",
            (book_id, util.get_today(), num_daily))
    else:
        res = db.execute("insert into schedule values (?,?,?,?,?,?)",
                         (uid, book_id, util.get_today(), 1, num_daily, 0))
    if res:
        return {'status': 200, 'msg': '操作成功'}
    else:
        return {'status': 404, 'msg': '操作失败'}
Beispiel #10
0
    def sample_place(self, place, features=util.FEATURES):
        ''' 
		this func sample the requested features of the place the robot at 
		'''
        today = util.get_today()

        speed_test = pyspeedtest.SpeedTest()
        ping = speed_test.ping()
        upload = speed_test.upload()
        download = speed_test.download()

        return (place, util.timeConvert(today['time']), today['day'], ping,
                upload, download)
Beispiel #11
0
def get_counters(name):
    """
    获取此计数器的若干个实例,如总计数,本日计数,本月计数,本年计数
    """
    time_periods = [
        "all",
        util.get_today(),
        util.get_week(),
        util.get_month(),
        util.get_year()
    ]

    res = [get_counter(name, time_period) for time_period in time_periods]
    return res
Beispiel #12
0
def set_result():
    uid = request.args.get('uid')
    word_id = request.args.get('word_id', type=int)
    mode = request.args.get('mode')
    result = request.args.get('result')
    print(uid, word_id, mode, result)
    # 设置总进度
    db.execute(
        "update schedule set current_progress=current_progress + 1 where uid=?",
        (uid, ))
    # 记录用户学习的单词
    db.execute("insert into [" + uid + "_table] values (?,?)",
               (word_id, "level 5"))

    # 更新当天记录
    res = db.execute_query("select * from record where uid=? and cur_date=?",
                           (uid, util.get_today()))
    if len(res) == 0:
        db.execute("insert into record values (?,?,?,?,?)",
                   (uid, util.get_today(), 0, 0, 0))
    db.execute(
        "update record set learn_day=learn_day+1 where uid=? and cur_date=?",
        (uid, util.get_today()))
    return {'status': 200, 'msg': '操作成功'}
Beispiel #13
0
def register():
    try:
        form = r.RegistrationForm(request.form)

        if request.method == "POST" and form.validate():

            email = form.email.data
            password = bcrypt.generate_password_hash(str(form.password.data), 10)
            name = form.name.data.capitalize()
            gender = form.gender.data
            year_of_birth = util.get_year(form.age.data)
            tos_check_date = util.get_today()

            # check username for duplicate
            try:
                result = users.insert_one(
                    {
                        "email":    email,
                        "password": password,
                        "name":     name,
                        "gender":   gender,
                        "yob":      year_of_birth,
                        "tos":      tos_check_date
                    }
                )
            except DuplicateKeyError, e:
                flash("That username is already taken, please choose another.", "error")
                return render_template('register.html', form=form)

            # No exception is good...
            flash("Thanks for registering!")

            session['logged_in'] = True
            session["token"] = util.generate_key()
            session['email'] = email
            session['name'] = name

            return redirect(url_for('index'))

    except Exception as e:
        flash(e.message, "error")
        logger.error("Issue with registering user.", exc_info=True)

    return render_template('register.html', form=form)
Beispiel #14
0
def push_all_history():
    stocks = load_all_stocks()
    for stock in stocks:
        push_history(stock)

def push_history(stock):
    x = stock.split('.')
    k = x[1].replace('ss','sh') +  x[0]
    red.delete(k)    
    records = loader.load_stock_history(stock)
    for r in records:         
        red.lpush(k,r) 

def push_records(day):
    stocks = loader.load_daily_stocks(day)
    for k,v in stocks.items():
        red.lpush(k,v) 


if __name__ == "__main__":
    latest_day = util.get_today()
    # push_history('600000.ss')

    print red.lrange('sh600000',0,10)
    # push_records('2015-03-23')
    # red.set('a','abc')
    # print red.get('a')
    # print red.delete('a')
    # print red.get('a')
Beispiel #15
0
            # 如果ga_category为空,则尝试从name中解析,假设name中以/分隔的第一个部分作为ga_category
            parts = name.split('/', 1)
            if len(parts) == 2:
                ga_category, name = parts
            else:
                ga_category = "counter"
        ga.track_event(ga_category, name, ga_misc_params)
        ga4.track_event(ga_category, name)
    elif ga_type == ga.GA_REPORT_TYPE_PAGE_VIEW:
        ga.track_page(name, ga_misc_params)
        ga4.track_event("page_view", name)
    else:
        logger.error(f"unknow ga_type={ga_type}")


time_periods = ["all", get_today()]
time_periods_desc = ["累积", "今日"]


def get_counters(name):
    """
    获取此计数器的若干个实例,如总计数,本日计数,本月计数,本年计数
    """
    res = [get_counter(name, time_period) for time_period in time_periods]
    return res


@try_except(show_exception_info=False, return_val_on_except=0)
def get_count(name, time_period):
    return get_counter(name, time_period).get('count', 0)
Beispiel #16
0
def test_get_today():
    assert get_today(now_for_test) == "20210806"
Beispiel #17
0
 def is_last_day(self):
     return format_time(parse_time(self.dtEndTime), "%Y%m%d") == get_today()
Beispiel #18
0
def run():
    if not util.is_trade_day():return 
    download.download_latest()
    latest_day = util.get_today()
    jump_p(latest_day)
Beispiel #19
0
    def is_last_day(self):
        from util import format_time, get_today, parse_time

        return format_time(parse_time(self.dtEndTime), "%Y%m%d") == get_today()
Beispiel #20
0
def run():
    if not util.is_trade_day():return 
    download.download_latest()
    latest_day = util.get_today()
    li =  load_daily_stocks(latest_day)
    jump_p(li)
Beispiel #21
0
def increase_counter(name):
    threading.Thread(target=increase_counter_sync, args=(name, ),
                     daemon=True).start()


def increase_counter_sync(name):
    try:
        logger.debug(f"update counter {name}")
        for counter in get_counters(name):
            counter.increment('count')
            counter.save()
    except Exception as exc:
        logger.debug(f"increase_counter {name} failedexc_info={exc}")


time_periods = ["all", util.get_today()]
time_periods_desc = ["累积", "今日"]


def get_counters(name):
    """
    获取此计数器的若干个实例,如总计数,本日计数,本月计数,本年计数
    """
    res = [get_counter(name, time_period) for time_period in time_periods]
    return res


def get_count(name, time_period):
    try:
        return get_counter(name, time_period).get('count', 0)
    except Exception as e:
Beispiel #22
0
    stocks = load_all_stocks()
    for stock in stocks:
        push_history(stock)


def push_history(stock):
    x = stock.split('.')
    k = x[1].replace('ss', 'sh') + x[0]
    red.delete(k)
    records = loader.load_stock_history(stock)
    for r in records:
        red.lpush(k, r)


def push_records(day):
    stocks = loader.load_daily_stocks(day)
    for k, v in stocks.items():
        red.lpush(k, v)


if __name__ == "__main__":
    latest_day = util.get_today()
    # push_history('600000.ss')

    print red.lrange('sh600000', 0, 10)
    # push_records('2015-03-23')
    # red.set('a','abc')
    # print red.get('a')
    # print red.delete('a')
    # print red.get('a')