Esempio n. 1
0
    def adapt_csv(self, valueDict):
        import parsedatetime.parsedatetime as pdt
        c = pdt.Constants()
        p = pdt.Calendar(c)

        self.app_date_string = valueDict["App Recvd"].strip()
        appDate = p.parse(valueDict["App Recvd"])
        if (appDate[1] == 1):
            self.app_date = date(*appDate[0][0:3]).isoformat()

        firstMiddle = valueDict["First Name"].partition(' ')
        self.name = {
            'last': valueDict["Last Name"].strip().title(),
            'first': firstMiddle[0].strip().title(),
            'middle': firstMiddle[2].strip().title(),
            'nickname': ''
        }

        self.address['street'] = valueDict["Address"].strip().title()
        self.address['city'] = valueDict["City"].strip().title()
        self.address['state'] = valueDict["State"].strip().upper()
        self.address['zip'] = valueDict["Zip"].strip()
        self.address['phone_day'] = valueDict["Phone (Day)"].strip()
        self.address['phone_eve'] = valueDict["Evening phone"].strip()
        self.address['phone_mbl'] = valueDict["Mobile phone"].strip()
        self.address['email'] = valueDict["Email"].strip()

        self.birth_date_string = valueDict["DOB"].strip()
        appDOB = p.parse(valueDict["DOB"])
        if (appDOB[1] == 1):
            self.birth_date = date(*appDOB[0][0:3]).isoformat()

        self.notes = {'other': valueDict["Comments"].strip()}
Esempio n. 2
0
    def adapt_csv(self, valueDict):
        import parsedatetime.parsedatetime as pdt
        c = pdt.Constants()
        p = pdt.Calendar(c)

        self.name = valueDict["FlightName"].strip()
        self.capacity = valueDict["FlightCapacity"]
        flightDate = p.parse(valueDict["FlightDate"])
        if (flightDate[1] == 1):
            self.flight_date = date(*flightDate[0][0:3]).isoformat()
Esempio n. 3
0
    def adapt_csv(self, valueDict):
        import parsedatetime.parsedatetime as pdt
        c = pdt.Constants()
        p = pdt.Calendar(c)

        appDate = p.parse(valueDict["app_date"])
        if (appDate[1] == 1):
            self.app_date = date(*appDate[0][0:3]).isoformat()

        self.name = {
            'last': valueDict["last_name"].strip().title(),
            'first': valueDict["first_name"].strip().title(),
            'middle': valueDict["middle_name"].strip().title(),
            'nickname': ''
        }

        self.address['street'] = valueDict["addr_street"].strip().title()
        self.address['city'] = valueDict["addr_city"].strip().title()
        self.address['county'] = valueDict["addr_county"].strip().title()
        self.address['state'] = valueDict["addr_state"].strip().upper()
        self.address['zip'] = valueDict["addr_zip"].strip()
        self.address['phone_day'] = valueDict["addr_phone_day"].strip()
        self.address['phone_eve'] = valueDict["addr_phone_eve"].strip()
        self.address['phone_mbl'] = valueDict["addr_phone_mbl"].strip()
        self.address['email'] = valueDict["addr_email"].strip()

        appDOB = p.parse(valueDict["birth_date"])
        if (appDOB[1] == 1):
            self.birth_date = date(*appDOB[0][0:3]).isoformat()

        self.gender = valueDict["gender"].strip().upper()
        self.shirt = {'size': valueDict["shirt_size"].strip().upper()}
        self.flight = {
            'status': 'Active',
            'status_note': '',
            'id': 'SSHF-Nov2013',
            'seat': '',
            'bus': 'None',
            'history': [],
            'confirmed_date': '',
            'confirmed_by': ''
        }
        self.preferred_airport = ''
        self.medical = {
            'limitations': '',
            'experience': '(FC) ' + valueDict["medical_experience"].strip(),
            'release': 'Y'
        }
        self.notes = {
            'service': valueDict["notes_service"].strip(),
            'previous_hf': valueDict["notes_previous_hf"].strip(),
            'other': valueDict["notes_other"].strip()
        }
        self.veteran = {'pref_notes': '(FC)', 'pairings': [], 'history': []}
Esempio n. 4
0
    def _clean_publish_date(self, bundle):
        if bundle.data['blog_post'] and 'publish_date' not in bundle.data:
            bundle.data['publish_date'] = datetime.datetime.now()
        elif bundle.data['publish_date'] == '':
            bundle.data['publish_date'] = datetime.datetime.now()
        elif bundle.data['blog_post']:
            c = pdt.Constants()
            p = pdt.Calendar(c)
            publish_date, result = p.parse(bundle.data['publish_date'])

            if result != 0:
                publish_date = time.strftime("%Y-%m-%d %H:%M:%S", publish_date)
            else:
                publish_date = datetime.datetime.now()

            bundle.data['publish_date'] = publish_date
        elif not bundle.data['blog_post']:
            bundle.data['publish_date'] = None

        return bundle
Esempio n. 5
0
    def __init__(self, **kwargs):
        self.config = {
            'journal': "journal.txt",
            'encrypt': False,
            'password': "",
            'default_hour': 9,
            'default_minute': 0,
            'timeformat': "%Y-%m-%d %H:%M",
            'tagsymbols': '@',
            'highlight': True,
            'linewrap': 80,
        }
        self.config.update(kwargs)

        # Set up date parser
        consts = pdt.Constants()
        consts.DOWParseStyle = -1  # "Monday" will be either today or the last Monday
        self.dateparse = pdt.Calendar(consts)
        self.key = None  # used to decrypt and encrypt the journal

        journal_txt = self.open()
        self.entries = self.parse(journal_txt)
        self.sort()
from datetime import datetime, timedelta


def create_milestone(index, milestone_name, milestone_date, is_major=False):
    return {
        'model': 'roadmap.Milestone',
        'pk': index,
        'fields': {
            'name': milestone_name,
            'date': milestone_date.strftime("%Y-%m-%d"),
            'is_major': is_major,
        }
    }


c = pdt.Constants(usePyICU=False)
c.BirthdayEpoch = 80
p = pdt.Calendar(c)

start = datetime.strptime("2011-01-01", "%Y-%m-%d")
end = datetime.strptime("2015-12-31", "%Y-%m-%d")

initial_data = []
last_index = 0
for index, dt in enumerate(rrule.rrule(rrule.MONTHLY, dtstart=start,
                                       until=end),
                           start=1):
    dtstring = "last thursday of %s" % dt.strftime("%B %Y")
    milestone_name = dt.strftime("%Y.%m")
    print dtstring
    milestone_date = datetime(*p.parseDateText(dtstring)[:6])
Esempio n. 7
0
    def adapt_csv(self, valueDict):
        import parsedatetime.parsedatetime as pdt
        c = pdt.Constants()
        p = pdt.Calendar(c)

        self.app_date_string = valueDict["Postmark Date"].strip()
        appDate = p.parse(valueDict["Postmark Date"])
        if (appDate[1] == 1):
            self.app_date = date(*appDate[0][0:3]).isoformat()
        else:
            self.app_date = date.today().isoformat()[0:10]

        self.name = {
            'last': valueDict["Last"].strip().title(),
            'first': valueDict["First"].strip().title(),
            'middle': valueDict["Middle"].strip().title(),
            'nickname': valueDict["Nick"].strip().title()
        }

        self.address['street'] = valueDict["Address"].strip().title()
        self.address['city'] = valueDict["City"].strip().title()
        self.address['county'] = "Unknown"
        self.address['state'] = valueDict["ST"].strip().upper()
        self.address['zip'] = valueDict["Zip Code"].strip()
        self.address['phone_day'] = valueDict["Phone Number"].strip()
        self.address['phone_mbl'] = valueDict["Secondary"].strip()
        self.address['email'] = valueDict["Email"].strip()

        self.birth_date_string = valueDict["DOB"].strip()
        appDOB = p.parse(valueDict["DOB"])
        if (appDOB[1] == 1):
            bd = date(*appDOB[0][0:3])
            if (bd is None):
                bd = date.today()
            if (bd > date.today()):
                bd = datetime(bd.year - 100, *bd.timetuple()[1:-2])
            self.birth_date = bd.isoformat()[0:10]

        self.gender = valueDict["Male/Female"].strip().upper()[:1]
        self.shirt = {
            'size':
            valueDict["Tshirt Size"].strip().upper().replace(
                "XXXXL", "4XL").replace("XXXL", "3XL").replace("XXL", "2XL")
        }
        self.guardian = {
            'pref_notes': valueDict["Assigned Guardian"].strip(),
            'id': '',
            'name': '',
            'history': []
        }
        self.vet_type = valueDict["Conflict"].split(
            ' ',
            1)[0].strip().title().replace("Korean",
                                          "Korea").replace("Wwii", "WWII")
        self.service['branch'] = valueDict["Branch"].strip()
        self.call = {
            'mail_sent': len(valueDict["Letter"].strip()) > 0,
            'history': []
        }
        self.flight = {
            'status': 'Active',
            'id': 'None',
            'seat': '',
            'group': '',
            'bus': 'None',
            'waiver': valueDict["Waiver"].strip().title() == "Yes",
            'history': []
        }
        self.medical = {
            'release': valueDict["Health"].strip().title() == "Yes"
        }
Esempio n. 8
0
def action_note(args):
    # Get action title (from arguments, or ask users if no argument supplied)
    args.action_title = args.action_title or    \
                        raw_input('Enter action title: ').strip()
    # Extract title-args that override command-line args
    extract_args_from_title(args)
    # Deduce when-context from title or argument (if supplied), or ask user
    if args.action_title[0] in '123456':
        when_prefix = args.action_title[0]
        # remove the prefix from the title
        args.action_title = ' '.join(args.action_title.split()[1:])
    else:
        when_prefix = args.when or raw_input(
            'Enter action when context (single digit): ').strip()
    if args.when and when_prefix <> args.when:
        # inconsistency! Go with the title..
        print 'Detected when-context inconsistency. Choosing', when_prefix
    if not when_prefix in '123456':
        raise RuntimeError('I don\'t like you (not in range 1..6)')
    # Get action context (from arguments, or ask user if not supplied).
    context = deduce_context(args.context)
    # Process reminder, if specified
    if args.reminder:
        import parsedatetime.parsedatetime as pdt
        cal = pdt.Calendar(pdt.Constants('he_IL', True))
        res_date, res_flag = cal.parse(args.reminder)
        if 1 == res_flag:
            # parsed as date - so use 9am as default time
            res_date = res_date[:3] + g_DefaultReminderTime + res_date[6:]
        if 0 == res_flag:
            # Not parsed at all
            print 'Failed parsing reminder date/time'
            args.action_title = 'FIX REMINDER %s' % (args.action_title)
            args.reminder = None
        else:
            # Convert reminder date/time object to UTC datetime string
            args.reminder = strftime('%Y%m%dT%H%M00Z',
                                     gmtime(mktime(res_date)))

    # Prepare template dictionary
    tmpl_params = {
        'WhenPrefix': when_prefix,
        'ActionTitle': args.action_title,
        'WhenContext': '%s-%s' % (when_prefix, when_mapping[int(when_prefix)]),
        'ActionContext': context,
        'Reminder': args.reminder and '<note-attributes>'  \
                '<reminder-order>%s</reminder-order>'  \
                '<reminder-time>%s</reminder-time>' \
                '<reminder-done-time>00001231T000000Z</reminder-done-time>' \
                '</note-attributes>' %  \
                (strftime('%Y%m%dT%H%M%SZ', gmtime()), args.reminder) or ''
        }

    # Apply template
    import_file_path = apply_template(args.template, tmpl_params)

    notebook = None
    if args.notebook:
        # Get list of notebook by running ENScript listNotebooks
        # it writes the notebooks the stdout, one per line
        p = Popen(['ENScript.exe', 'listNotebooks'], stdout=PIPE)
        notebooks, _ = p.communicate()
        notebooks = [nb.strip() for nb in notebooks.split('\n')]

        def get_notebook(query):
            # Try a best-effort exact match
            query_matcher = re.compile('(.*)%s(.*)' % (re.escape(query)),
                                       re.IGNORECASE)
            min_miss_len = max(map(len, notebooks))
            notebook = None
            for nb in notebooks:
                qm = query_matcher.match(nb)
                if qm:
                    miss_len = len(qm.group(1)) + len(qm.group(2))
                    if 0 == miss_len:
                        # Perfect match! Return immediately!
                        return nb
                    if miss_len < min_miss_len:
                        min_miss_len = miss_len
                        notebook = nb
            # If had any luck, return now
            if notebook:
                return notebook
            # Otherwise, try maximal word-overlap matching
            def to_words(str):
                return set(str.lower().replace('-', ' ').split())

            in_words = to_words(query)
            max_intersect = 0
            for nb in notebooks:
                nb_words = to_words(nb)
                intersection = len(nb_words.intersection(in_words))
                if intersection > max_intersect:
                    max_intersect = intersection
                    notebook = nb
            return notebook

        notebook = get_notebook(args.notebook)

    timestr = strftime('%Y%m%dT%H%M00')
    # Import the note to Evernote
    # (into specific notebook if supplied, or default one otherwise)
    call_args = ['importNotes', '/s', import_file_path]
    if notebook:
        call_args.append('/n')
        call_args.append(notebook)
    call_enscript(call_args)

    # Open the note in a separate window after importing (if flagged to do so)
    if args.open_note:
        open_first_note('created:%s tag:.Action' % (timestr))