コード例 #1
0
 def local_to_utc(self, dt_str):
     # Function that converts a date string to utc and returns date string
     dt = dateutil.parser.parse(dt_str, dayfirst=True)
     if ':' in dt_str:
         return vpapi.local_to_utc(dt, to_string=True)
     else:
         return dt.strftime('%Y-%m-%d')
コード例 #2
0
def sk_to_utc(dt_str):
	"""Converts Slovak date(-time) string into ISO format in UTC time."""
	match = re.search(SK_MONTHS_REGEX, dt_str, re.IGNORECASE)
	if match:
		month = match.group(0)
		dt_str = dt_str.replace(month, '%s.' % SK_MONTHS[month[:3].lower()])
	dt = dateutil.parser.parse(dt_str, dayfirst=True)
	if ':' in dt_str:
		return vpapi.local_to_utc(dt, to_string=True)
	else:
		return dt.strftime('%Y-%m-%d')
コード例 #3
0
ファイル: speeches.py プロジェクト: KohoVolit/scraper-psp.cz
def cs_to_utc(dt_str):
    """Converts Czech date(-time) string into ISO format in UTC time."""
    match = re.search(CS_MONTHS_REGEX, dt_str, re.IGNORECASE)
    if match:
        month = match.group(0)
        if month[:3] == 'čer':
            if len(month) > 6:
                monthn = 7
            else:
                monthn = 6
        else:
            monthn = CS_MONTHS[month[:3].lower()]
        dt_str = dt_str.replace(' ', '').replace(month, '%s.' % monthn)
    dt = dateutil.parser.parse(dt_str, dayfirst=True)
    if ':' in dt_str:
        return vpapi.local_to_utc(dt, to_string=True)
    else:
        return dt.strftime('%Y-%m-%d')
コード例 #4
0
def saveallmotionsandvoteevents(hl_hlasovani): 
    global test
    organizations = {}
    for row in hl_hlasovani:
        try: 
            organizations[row[1].strip()]
        except:
            organizations[row[1].strip()] = vpapi.get('organizations', where={'identifiers': {'$elemMatch': {"identifier": row[1].strip(), "scheme": "psp.cz/organy"}}}) 
        r_org = organizations[row[1].strip()]
      #r_org = vpapi.get('organizations', where={'identifiers': {'$elemMatch': {"identifier": row[1].strip(), "scheme": "psp.cz/organy"}}})
      
        motion = {
            "id": row[0].strip(),
            "organization_id": r_org["_items"][0]['id'],
            "requirement": guess_majority(row[12],row[11]),
            "result": result2result(row[14].strip()),
            "text": row[15].strip(),
            #'identifiers': [{'identifier': row[0].strip(), 'scheme': 'psp.cz/hlasovani'}]
            "sources": [{'url':"http://www.psp.cz/sqw/hlasy.sqw?g=" + row[0].strip()}]
        }
        print("motion: " + motion['id'])
        if int(motion['id']) > 60536:
            r_motion = savemotion(motion)
      
            #r_motion = vpapi.get('motions', where={'sources': {'$elemMatch': {"identifier": row[0].strip(), "scheme": "psp.cz/hlasovani"}}}) #<-wrong: should be with "sources"
            if r_motion["_status"] == "OK":
                vote_event = {
                    "id": row[0].strip(),
                    "motion_id": r_motion['id'],
                    'identifier': row[0].strip(),
                    #"legislative_session_id": row[2].strip(),  #not implemented in api yet
                    "start_date": vpapi.local_to_utc(scrapeutils.cs2iso(row[5].strip() + "T" + row[6].strip())),
                    "result": result2result(row[14].strip()),
                }
                r_voteevent = savevoteevent(vote_event)
                test[row[0].strip()] = {"id":row[0].strip(),"ve":True}
                logging.info('Motion and vote-event saved: ' + str(r_motion['id']))
コード例 #5
0
def local_to_utc(dt_str):
    dt = dateutil.parser.parse(dt_str, dayfirst=True)
    if ':' in dt_str:
        return vpapi.local_to_utc(dt, to_string=True)
    else:
        return dt.strftime('%Y-%m-%d')