Esempio n. 1
0
def create_fixtures():
    loader = Loader('opennews', project_label='Open News',
                    project_settings={},
                    source_url=DEFAULT_SOURCE_URL)
    
    import_schema(loader.project, StringIO(SCHEMATA))

    reader = unicodecsv.reader(StringIO(DATA))
    reader.next()
     
    for record in reader:
        fellow = loader.make_entity(['fellow'])
        fellow.set('name', record[0])
        fellow.set('twitter_handle', record[1])
        fellow.save()
     
        news_org = loader.make_entity(['news_organization'])
        news_org.set('name', record[4])
        news_org.set('url', record[5])
        news_org.save()
     
        fellowship = loader.make_relation('fellowship', fellow, news_org)
        fellowship.set('start_date', record[2])
        fellowship.set('end_date', record[3])
        fellowship.save()

    loader.persist()
Esempio n. 2
0
def create_fixtures():
    loader = Loader('opennews',
                    project_label='Open News',
                    project_settings={},
                    source_url=DEFAULT_SOURCE_URL)

    import_schema(loader.project, StringIO(SCHEMATA))

    reader = unicodecsv.reader(StringIO(DATA))
    reader.next()

    for record in reader:
        fellow = loader.make_entity(['fellow'])
        fellow.set('name', record[0])
        fellow.set('twitter_handle', record[1])
        fellow.save()

        news_org = loader.make_entity(['news_organization'])
        news_org.set('name', record[4])
        news_org.set('url', record[5])
        news_org.save()

        fellowship = loader.make_relation('fellowship', fellow, news_org)
        fellowship.set('start_date', record[2])
        fellowship.set('end_date', record[3])
        fellowship.save()

    loader.persist()
Esempio n. 3
0
 
# This source URL will be applied to all properties without their own lineage:
DEFAULT_SOURCE_URL = 'http://www.opennews.org/'
 
# Any settings (free-form dict):
PROJECT_SETTINGS = {}
 
loader = Loader('opennews', project_label='opennews',
    project_settings=PROJECT_SETTINGS, source_url=DEFAULT_SOURCE_URL)
 
reader = unicodecsv.reader(open('fellows.csv'))
reader.next()
 
for record in reader:
    fellow = loader.make_entity(['fellow'])
    fellow.set('name', record[0])
    fellow.set('twitter_handle', record[1])
    fellow.save()
 
    news_org = loader.make_entity(['news_organization'])
    news_org.set('name', record[4])
    news_org.set('url', record[5])
    news_org.save()
 
    fellowship = loader.make_relation('fellowship', fellow, news_org)
    fellowship.set('start_date', record[2])
    fellowship.set('end_date', record[3])
    fellowship.save()

loader.persist()
Esempio n. 4
0
# coding: utf-8
from normality import normalize
import csv
import normality
from grano.logic import Loader
rows = ["id", "name", "sort_name", "email", "twitter", "facebook", "group", "group_id", "area_id", "area", "chamber", "term", "start_date", "end_date", "image", "gender"]


if __name__ == "__main__":

    loader = Loader('senegal', project_label='Senegal')
    person = loader.make_entity("politician")


    with open('senegal/senegal-politicians.csv', 'r') as csvfile:
        records_reader = csv.reader(csvfile, delimiter=",")
        for row in records_reader:
            for x in range(0, len(rows)):
                #print "%s :: %s" % (rows[x], row[x])
                if row[x]:
                    val = normalize(str(row[x]))
                    person.set( rows[x], val )
            person.save()
        loader.persist()