Esempio n. 1
0
def get_medals(years, season):
	for year in years:
		print year

		medal_chart = olympic_stats(str(year), season)
		rows = medal_chart.split('\n')

		session = models.create_db_session()
		for row in rows:
			data = row.split(' | ')
			if data[0]=='country': # header
				continue

			print data[0]

			c = models.Country(name=data[0])
			matches = c.duplicates(session)
			if not matches:
				session.add(c)
				session.commit()
				c.reload_stats(session)
			else:
				c = matches[0]
			m = models.Medals(country_id=c.id, year=str(year), gold=data[1], silver=data[2], bronze=data[3])
			matches = m.duplicates(session)
			if not matches:
				session.add(m)
				session.commit()
		models.end_db_session(session)
Esempio n. 2
0
	for key in vcard_json.keys():
		if 'EMAIL' in key:
			e = models.Email(address=vcard_json[key], contact_id=c.id)
			matches = e.duplicates(session)
			if not matches:
				session.add(e)
			# attributes --> key.split(';')[1:])
		if 'TEL' in key:
			p = models.Phone(number=vcard_json[key], contact_id=c.id)
			matches = p.duplicates(session)
			if not matches:
				session.add(p)
		if 'ADR' in key:
			a = models.Address(address=vcard_json[key], contact_id=c.id)
			matches = a.duplicates(session)
			if not matches:
				session.add(a)
		if 'URL' in key:
			w = models.Webpage(address=vcard_json[key], contact_id=c.id)
			matches = w.duplicates(session)
			if not matches:
				session.add(w)

	session.commit()
	models.end_db_session(session)




Esempio n. 3
0
from db import models

session = models.create_db_session()

results = session.query(models.SomeTable).filter(models.SomeTable.field1>0)

print results

models.end_db_session(session)