示例#1
0
async def chekDate(date,message):
  global command
  try:
    time.striptime(date, 'dd.mm.YYYY')
    return True
  except ValueError:
    await message.answer(text="Неправильный формат даты")
    command = 0
示例#2
0
def match_var(Excelpath,
              Outputpath,
              filetype='both',
              existdate='True',
              backdate=''):
    try:
        dff = pd.read_excel(str(Excelpath))
    except:
        dff = pd.read_csv(str(Excelpath))
    print dff.columns()
    print u'请确认身份证、手机号、回溯时间是否为uid、umboile、date,是则输入1,否则输入为0'
    check_column = raw_input("")
    if str(check_column) == '0':
        id_name = raw_input('需要修改的身份证列名:')
        mobile_name = raw_input('需要修改的手机号列名:')
        date_name = raw_input('需要修改的回溯时间列名:')
        dff = dff.rename(
            columns={
                unicode(id_name): 'uid',
                unicode(mobile_name): 'umobile',
                unicode(date_name): 'date'
            })
        dff = dff.drop([x for x in dff.columns if re.search('Unnamed', x)],
                       axis=1)
        for i in dff.columns:
            dff[i] = dff[i].astype(str)
        if existdate == 'True':
            dff['loan_date_unix'] = dff['date'].apply(lambda x: time.mktime(
                time.striptime(str(parse(x))[:19], '%Y-%m-%d %H:%M:%S')))
        else:
            dff['loan_date_unix'] = time.mktime(
                time.striptime(
                    str(parse(backdate))[:19], '%Y-%m-%d  %H:%M:%S'))

        dff['umobile'] = dff['umobile'].apply(lambda x: x[:11])
        data = hc.createDataFrame(dff)
        d = hc.read.parquet('/user/sujun.cen/temp/icd')
        m = hc.read.parquet('/user/sujun.cen/temp/md')
        if filetype == 'both':
            df = data.join(d, data.uid == d.id, 'leftouter')
            df1 = df.join(m, df.umobile == m.mobile, 'leftouter')
            df2 = df1.rdd.map(map_time_all).map(stats_fun_for_all_value)
            df2.toDF().write.parquet(str(Outputpath), 'overwrite')
        elif filetype == 'id':
            df = data.join(d, data.uid == d.id, 'leftouter')
            df1 = df.rdd.map(map_time_id).map(stats_fun_for_id_value)
            df1.toDF().write.parquet(str(Outputpath), 'overwrite')
        else:
            df = data.join(m, data.umobile == m.mobile, 'leftouter')
            df1 = df.rdd.map(map_time_mobile).map(stats_fun_for_mobile_value)
            df1.toDF().write.parquet(str(Outputpath), 'overwrite')
示例#3
0
def timestamps_minus_born_time(raw_file):
    dataset=open(raw_file,'r')
    header=dataset.readline().rstrip('\n').split(',')
    ts_index=header.index('timestamps')
    bt_index=header.index('born_time')

    store=open(raw_file+'-ts_bt','w')
    store.write('timestamps_minus_born_time\n')

    for record in dataset:
        attributes=record.rstrip('\n').split(',')
        timestamps=int(attributes[ts_index])
        born_time=attributes[bt_index]

        try:
            born_time_tricks=int(time.mktime(time.striptime(born_time,'%y%m%H%M%S')))
        except:
            born_time_tricks=timestamps+1
        store.write(str(timestamps-born_time_tricks)+'\n')
     dataset.close()
     store.close()
import os
import time

count = 0
kept = 0
deleted = 0

for (root, dirs, files) in os.walk('.'):
    for filename in files:
        if filename.endswitch('.txt'):
            f = open(filename, 'r')
            sdate = f.readline()
            f.close()
            pdate = time.striptime(sdate, '%Y%-m%-d\n')
            if pdate.tm_year > 2002:
                kept += 1
            else:
                os.remove(filename)
            deleted += 1
        count += 1
print('Total files' + str(count))
print('kept' + str(kept))
print('deleted' + str(deleted))
def getminutes(t):
	x = time.striptime(t, '%H:%M')
	return x[3]*60+x[4]
#!/usr/bin/env python
#
# This file has been provided as a starting point. You need to modify this file.
# Reads whole lines stdin; writes key/value pairs to stdout
# --- DO NOT MODIFY ANYTHING ABOVE THIS LINE ---

import sys
import re
import time

if __name__ == "__main__":
    for line in sys.stdin:
        for word in line.split():
            if re.match('\[\d\d/[a-zA-Z]{3}\/\d{4,}:\d\d:\d\d:\d\d\Z', word):
                date = time.striptime(word, '[%d/%b/%Y:%H:%H:%S')
                result = str(date.tm_year)
                result += '-'
                if (date.tm_mon < 10):
                    result += '0'
                result += str(date.tm_mon)
                sys.stout.write("{}\t1\n".format(result))