Created
January 30, 2019 17:33
-
-
Save nruigrok/f1fdac8be730334f2de7ef669e222f8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import django | |
django.setup() | |
from amcat.models import Article,Project, CodingJob, CodingSchemaField, ArticleSet | |
import sys, datetime, csv | |
cjs = list(CodingJob.objects.filter(project__id=1)) | |
known_media = {} # {alias: name} | |
beter_media={} | |
with open('mediabzk.csv') as csvfile: | |
media_reader = csv.DictReader(csvfile, delimiter=",") | |
for row in media_reader: | |
fout = row['media'] | |
goed = row['med1'] | |
beter = row['mediadetail'] | |
known_media[fout] = goed | |
beter_media[fout] = beter | |
missing_media = set() | |
for i, cj in enumerate(cjs): | |
fout = False | |
for ca in cj.coded_articles.only("article__id"): | |
med=ca.article.get_property("medium") | |
if med in known_media: | |
medv=known_media[med] | |
if med == medv: | |
continue | |
print(ca.article.id, ":", med, "-->", medv) | |
ca.article.set_property("medium", medv) | |
if med in beter_media: | |
medb=beter_media[med] | |
if med == medb: | |
continue | |
ca.article.set_property("mediumspecifiek",medb) | |
print(ca.article.id, "mediumspecifiek:", medb) | |
# ca.article.save() | |
else: | |
missing_media.add(med) | |
break # only do one codingjob for now | |
print("*** Missing media:") | |
for x in missing_media: | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment