Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Script to set news_term on organisations within a CSV file.
- CSV format:
- name,news_term
- """
- import csv
- import click
- from vizibl.helpers.factory import create_app
- from vizibl.models import db, Organisation
- def get_organisation(name):
- org = db.session.query(Organisation).filter(Organisation.name == name)
- return org.one_or_none()
- @click.command()
- @click.argument('input', type=click.Path(exists=True))
- def run(input):
- with open(input, 'r') as csvfile:
- _csv = csv.reader(csvfile)
- for row in _csv:
- org = get_organisation(row[0])
- if org:
- org.news_term = row[1]
- db.session.commit()
- if __name__ == '__main__':
- app = create_app()
- with app.test_request_context():
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement