Beispiel #1
0
def mapper():
    for line in sys.stdin:
        data = line.strip().split("\t")
        if len(data) == 6:
            data, time, store, item, cost, payment = data
            day = datetime.striptime(date, "%Y-%m-%d").weekday()
            print "{0}\t{1}".format(day, cost)
 def process_item(self, item, spider):
     item['level'] = int(item['level'][1:])
     item['join_date'] = datetime.striptime(item['join_date'].split()[0],
                                            '%Y-%m-%d').date()
     item['learn_courses_num'] = int(item['learn_courses_num'])
     self.session.add(User(**item))
     return item
def get_ebola_data(user_date):

    data = requests.get("https://ebola-outbreak.p.mashape.com/cases",
      headers={
        "X-Mashape-Key": "5wOSqCitXnmshZqducSXXSpnMgA0p1SQfb8jsnticr7ef6tPYu"
      }
    )
    
    data = data.text
    data = json.loads(data)
    date_user = datetime.striptime(user_date,'%Y-%m-%d')
    
    for entry in data:
        cases = entry['cases']

        date_split = entry['date'][0:10]

        date = datetime.strptime(date_split, 
                             '%Y-%m-%d')



        deaths = entry['deaths']

        if date == date_user:
            response = deaths
    
        else:
            response = 0
    
    
    return response
Beispiel #4
0
def getNewsdetial(newsurl):
    res = requests.get(newsurl)
    res.encoding = 'utf-8'
    soup = BeautifulSoup(res.text, 'html.parser')
    newsTitle = soup.select('.page-headerh1')[0].text.strip()
    nt = datetime.striptime(
        soup.select('.time-source')[0].contents[0].strip(), '%Y年%m月%d日%H:%M')
    newsTime = datetime.strftime(nt, '%Y-%m-%d %H:%M')
    newsArticle = getnewsArticle(soup.select('.article p'))
    newsAuthor = newsArticle[-1]
    return newsTitle, newsTime, newsArticle, newsAuthor
Beispiel #5
0
def create_order():
    house_id = request.get_json().get("housed_id")
    start_date_str = request.get_json().get("start_date")
    end_date_str = request.get_json().get("end_date")

    if not all([house_id, start_date_str, end_date_str]):
        return jsonify(errno=RET.PARAMERR, errmsg="参数不完整")
    try:
        house = House.query.get(house_id)
        start_date = datetime.striptime(start_date_str, "%Y-%m-%d")
        end_date = datetime.strptime(end_date_str, "%Y-%m-%d")

    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errrno=RET.DBERR, errmsg="查询异常")

    if not house:
        return jsonify(errno=RET.NODATA, errmsg="=该房子不存在")

    try:
        conflict_orders = Order.query.filter(start_date < Order.end_date,
                                             end_date > Order.start_date)

    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="查询订单异常")
    if conflict_orders:
        return jsonify(errno=RET.DATAERR, errmsg="该房子时间段内已被锁定")
    order = Order()
    days = (end_date - start_date).days
    order.user_id = g.user_id
    order.user_id = g.user_id
    order.house_id = house_id
    order.begin_date = start_date
    order.days = days
    order.house_price = house.price
    order.amount = house.price * days

    try:
        db.session.add(order)
        db.session.commit()

    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="订单创建失败")

    return jsonify(errno=RET.OK, errmsg="创建成功")
Beispiel #6
0
def populateCoD():
    db = get_db()
    accNum1 = [line.rstrip('\n') for line in open('accNum.txt')]
    accNum1 = list(map(int, accNum1))
    cNum1 = [line.rstrip('\n') for line in open('cNumber.txt')]
    lastname1 = [line.rstrip('\n') for line in open('last_name.txt')]
    cNum1 = list(map(float, cNum1))
    cvc1 = [line.rstrip('\n') for line in open('CVC_data.txt')]
    cvc1 = list(map(float, cvc1))
    date1 = [line.rstrip('\n') for line in open('expDate.txt')]
    for x in range(0, 1000):
        accNum2 = accNum1[x]
        cNum2 = cNum1[x]
        lastname2 = lastname1[x]
        cvc2 = cvc1[x]
        date2 = date1[x]
        date3 = datetime.striptime(date2, '%m%d%y')
        db.execute(
            "insert into CreditDebit(AccNum, nameOnCard, cardNum, CVC, expirationDate) values (accNum2, lastname2, cNum2, cvc2, date3); "
        )
    db.commit()
Beispiel #7
0
def is_future_data(self, cr, uid, ids, my_date, context=None):
    if datetime.striptime(
            my_date,
            DEFAULT_SERVER_DATE_FORMAT).date() > datetime.now().date():
        return False
    return my_date


#    _columns = {
#    	'name' : fields.Char(size=64),
#    	'description' : fields.Html()
#    }

# class lists(models.Model):
#     _name = 'lists.lists'

#     name = fields.Char()
#     value = fields.Integer()
#     value2 = fields.Float(compute="_value_pc", store=True)
#     description = fields.Text()
#
#     @api.depends('value')
#     def _value_pc(self):
#         self.value2 = float(self.value) / 100
from matplotlib import pyplot as plt
from datetime import datetime

filename = 'sitka_weather_072014.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    # 查看第一行每一列的信息(表头)
    # for index, column_header in enumerate(header_row):
    #     print(index, column_header)

    # 取出某一列或几列的所有值
    dates, highs = [], []
    for row in reader:
        current_date = datetime.striptime(row[0], "%Y-%m-%d")
        dates.append(current_date)
        high = int(row[1])
        highs.append(high)

    # 根据数据绘制图形
    fig = plt.figure(dpi=128, figsize=(10, 6))
    plt.plot(dates, highs, c='red')
    # 设置图形的格式
    plt.title("Daily high temperatures, July", fontsize=14)
    plt.xlabel('', fontsize=16)
    # 绘制斜的日期标签
    fig.autofmt_xdate()
    plt.ylabel("Temperature(F)", fontsize=16)

    # 设置刻度标记的大小
Beispiel #9
0
intervals = sorted(intervals, key = lambda X: (X[0], X[1]), reverse = False)
for interval in intervals:
    if not heap:
        heappush(heaps, interval)
    elif interval[0] >= heaps[-1][1]:
        heaps[-1][1] = interval[1]
    else:
        heappush(heaps, interval)
return len(heaps)


from datetime import timedelta
start = datetime(2011, 1, 7)
dt2 = start + timedelta(12)
dt3 = start - 2 * timedelta(12)
dt2.days
value = "2011-01-03"

datetime.striptime(value, '%Y-%m-%d')











from datetime import datetime

# striptime()日期字符串作为第一个实参,第二个实参告诉python怎么设置日期的格式
first_date = datetime.striptime('2014-7-1', '%Y-%m-%d')
print(first_time)

# %A 星期的名称,如Monday
# %B 月份名,如January
# %m 用数字表示的月份(01-12)
# %d 用数字表示月份中的一天(01-31)
# %Y 四位的年份,如2015
# %y 两位的年份,如15
# %H 24小时制的小时数(00-24)
# %I 12小时制的小时数(01-12)
# %p am或pm
# %M 分钟数(00-59)
# %S 秒数(00-61)
print "Download calls..."
path = "%s/%s/%s/bus_time_%s.csv.xz" % (server, year, yearmonth,
                                        date.replace("-", ""))
destination = "%s/calls/%s.csv.xz" % (datadirectory, date)
comm = "curl -o %s %s; unxz %s" % (destination, path, destination)
os.system(comm)

# read calls
print "Read calls..."
fname = destination[:-3]
calls = pd.read_csv(fname)

calls = calls[['timestamp', 'trip_id', 'next_stop_id', 'dist_from_stop']]
calls['timestamp'] = calls['timestamp'].apply(
    lambda x: datetime.strptime(x, "%Y-%m-%dT%H:%M:%SZ") - timedelta(hours=5))
calls = calls[calls['timestamp'] >= datetime.striptime(date, "%Y-%m-%d")]
calls = calls[calls['timestamp'] < datetime.striptime(date, "%Y-%m-%d") +
              timedelta(days=1)]


def get_route(x):
    try:
        return x.split("_")[2]
    except:
        return np.nan


calls['route_id'] = calls.trip_id.apply(lambda x: get_route(x))
calls = calls.sort_values(["trip_id", "timestamp"]).dropna()
calls.index = range(len(calls))
Beispiel #12
0
def age(born):
    born = datetime.striptime(born, "%d/%m/%Y").date()
    today = date.today()
    delta = today - born
    return int(delta.days / 365.25, 0)
def get_weekday(date_str):
    return datetime.striptime(date_str.decode('ascii'),
                              "%d-&m-%y").date().weekday()
Beispiel #14
0
row = next(csv_file)

high = []

for row in csv_file:
    high.append(int(row[5]))
print(high)

from datetime import datetime

high = []
date = []

for row in csv_file:
    high.append(int(row[5]))
    the_date = datetime.striptime(row[2], "%Y-%m-%d")
    date.append(the_date)

import matplotlib.pyplot as plt

fig = plt.figure()

plt.plot(date, high, c="red")
plt.title('Daily High Temp', fontsize=20)
plt.ylabel('Temperature (F)', fontsize=18)
plt.tick_params(axis='both', labelsize=16)

fig.autofmt_xdate()

plt.show()
    'Rotth?user Weg 636', '88, avenue de l? Union Centrale'
],
               'Not Provided',
               inplace=True)

df.to_csv("CleanedDatainStore.csv", index=False, header=None)

#reads the second sheet
cf = pd.read_csv("DataInCentralDatabase.csv", engine='python')
cf = pd.read_csv("DataInCentralDatabase.csv", header=None)
cf.fillna(value="N/A", inplace=True)

iterdate = iter(cf[9])
next(iterdate)
for i in iterdate:
    date = i
    date = datetime.striptime(date, '%Y%m%d').strftime('%d/%m%y')

cf[4].replace('Alexandria_stroe', 'Alexandria_store', inplace=True)
cf[11].replace('Alexandria_stroe', 'Alexandria_store', inplace=True)
trash = [
    'o?str 5538', 'eiter Weg 7765', 'ostenweg 2428', 'ostfach 99 92 92',
    'rue de Linois', 'Mo str 5538', 'otth?user Weg 636', 'eiderplatz 662',
    '8, avenue de l? Union Centrale', '68, avenue de l?Europe',
    'Ootth user Weg 636', 'unckerstr 22525'
]
cf[19].replace([trash], 'Unknown', inplace=True)
cf[25].replace(['9-Mar', '9-May'], 'Unknown', inplace=True)

cf.to_csv("CleanedCD.csv", index=False, header=None)
Beispiel #16
0
now = datetime.now()
print(now)

#获取指定日期和时间
dt = datetime(2015, 4, 19, 12, 20)

#一个datetime类型转换为timestamp
dt.timestamp()
#反过来
t = 1429417200.0
print(datetime.fromtimestamp(t))
#转换到UTC标准时区的时间
print(datetime.utcfromtimestamp(t))

#str转为datetime
cday = datetime.striptime('2015-6-1 18:19:59', '%Y-%m-%d %H:%M:%S')
#反过来
now = datetime.now()
print(now.strftime('%a,%b %d %H:%M'))

#datetime加减
from datetime import datetime, timedelta
now = datetime.now
now + timedelta(hours=10)
now - timedelta(days=1)
now + timedelta(days=2, hours=12)

#本地时间转换为UTC时间

#强制设置时区
from datetime import datetime, timedelta, timezone