async def advent_calendar_loop(self):
     now = datetime.now()
     for day in self.advent_calendar:
         if not day["opened"]:
             due_date = utils.date_from_string(day["date"])
             if due_date <= now:
                 await self.open(day)
             else:
                 return
Beispiel #2
0
 def __init__(self, *args, **kwargs):
     '''
     Create a schedule for SquashCity
     Expect the command in the following format:
     [DAYNAME_START] [DAYNAME_END] [TIME_START] [TIME_END]
     If DAYNAME_START is missing it is defaulted to today
     If DAYNAME_END is missing it is defaulted to today
     If TIME_START is missing it is defaulted to now()
     If TIME_END is missing it is defaulted to 23:59
     
     The SquashCity schedule is processed by the squashcity daemon 
     '''
     self.username = kwargs['username']
     args = ''.join(args)
     match = re.match(pat, args)
     if not match:
         raise ValueError('Squash - incorrect parameters')
     from_day, to_day, from_time_h, = match.groups()[:3]
     from_time_m, to_time_h, to_time_m = match.groups()[3:]
     if to_day == None: to_day = from_day
     if from_time_h == None:
         tm_now = datetime.now().time()
         from_time_h, from_time_m = tm_now.hour, tm_now.minute
     if to_time_h == None:
         to_time_h = 23
         to_time_m = 59
     if from_time_m == None: from_time_m=0
     if to_time_m == None: to_time_m = 0
     from_time_h, from_time_m = int(from_time_h), int(from_time_m)
     to_time_h, to_time_m = int(to_time_h), int(to_time_m)
     try:
         _ = time(from_time_h, from_time_m)
         _ = time(to_time_h, to_time_m)
     except ValueError:
         raise ValueError('Squash - incorrect parameters')
     d_from = utils.date_from_string(from_day, from_time_h, from_time_m)
     d_to = utils.date_from_string(to_day,
                                   reference_day=d_from, 
                                   hour=to_time_h, 
                                   minute=to_time_m)
     if d_from > d_to:
         raise ValueError("Squash - start date greater than end date")
     self.d_from, self.d_to = d_from, d_to
Beispiel #3
0
 def __init__(self, *args, **kwargs):
     '''
     Create a schedule for SquashCity
     Expect the command in the following format:
     [DAYNAME_START] [DAYNAME_END] [TIME_START] [TIME_END]
     If DAYNAME_START is missing it is defaulted to today
     If DAYNAME_END is missing it is defaulted to today
     If TIME_START is missing it is defaulted to now()
     If TIME_END is missing it is defaulted to 23:59
     
     The SquashCity schedule is processed by the squashcity daemon 
     '''
     self.username = kwargs['username']
     args = ''.join(args)
     match = re.match(pat, args)
     if not match:
         raise ValueError('Squash - incorrect parameters')
     from_day, to_day, from_time_h, = match.groups()[:3]
     from_time_m, to_time_h, to_time_m = match.groups()[3:]
     if to_day == None: to_day = from_day
     if from_time_h == None:
         tm_now = datetime.now().time()
         from_time_h, from_time_m = tm_now.hour, tm_now.minute
     if to_time_h == None:
         to_time_h = 23
         to_time_m = 59
     if from_time_m == None: from_time_m = 0
     if to_time_m == None: to_time_m = 0
     from_time_h, from_time_m = int(from_time_h), int(from_time_m)
     to_time_h, to_time_m = int(to_time_h), int(to_time_m)
     try:
         _ = time(from_time_h, from_time_m)
         _ = time(to_time_h, to_time_m)
     except ValueError:
         raise ValueError('Squash - incorrect parameters')
     d_from = utils.date_from_string(from_day, from_time_h, from_time_m)
     d_to = utils.date_from_string(to_day,
                                   reference_day=d_from,
                                   hour=to_time_h,
                                   minute=to_time_m)
     if d_from > d_to:
         raise ValueError("Squash - start date greater than end date")
     self.d_from, self.d_to = d_from, d_to
Beispiel #4
0
def parse_date(s):
    """Parse a string from a date argument.

    :param s: String should be in format of YYYY-mm-dd
    :returns: datetime
    """
    try:
        return utils.date_from_string(s)
    except ValueError:
        raise argparse.ArgumentTypeError(
            "Not a valid date: '{0}'. Should be YYYY-mm-dd.".format(s)
        )
def parser_bank(filename, header_fields):
    result = []
    with open(filename) as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
                obj = {
                    'date': date_from_string(row[header_fields['date']], header_fields['date_format']),
                    'description': row[header_fields['description']].strip(),
                    'amount': header_fields['sign'] * float(row[header_fields['amount']])
                }
                result.append(obj)
    return result    
Beispiel #6
0
def parser_bank(filename, header_fields):
    result = []
    with open(filename) as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            obj = {
                'date':
                date_from_string(row[header_fields['date']],
                                 header_fields['date_format']),
                'description':
                row[header_fields['description']].strip(),
                'amount':
                header_fields['sign'] * float(row[header_fields['amount']])
            }
            result.append(obj)
    return result
def create_advent_calendar():
    advent_calendar = []
    startdate = utils.date_from_string(
        os.getenv("DISCORD_ADVENT_CALENDAR_START")).astimezone()

    for i in range(0, 24):
        advent_calendar.append({
            "number":
            i + 1,
            "date":
            utils.date_to_string(startdate + timedelta(days=i)),
            "assigned":
            False,
            "opened":
            False
        })

    return advent_calendar
Beispiel #8
0
import os
import datetime
import pandas as pd
import numpy as np
import utils

indir = "data_derived"
events = pd.DataFrame.from_csv(os.path.join(indir, "events.csv"),
                               index_col=False)
events['date'] = utils.date_from_string(df=events, date_str="holddate")

names = events.name.unique()
gids = events.gempermid.unique()

start_date = datetime.date(2009, 1, 1)
end_date = datetime.date(2018, 1, 1)

incr_days = 30
diter = utils.date_iterator(first=start_date,
                            last=end_date,
                            incr_days=incr_days)

fulldf = pd.DataFrame()
prevfull = pd.DataFrame(
    columns=['name', 'gempermid', 'pctchouthld', 'state', 'pct'])
prev_date = start_date - datetime.timedelta(incr_days)
evlist = []
for date in diter:
    print(date)
    datedf = pd.DataFrame()
    newev = dict()