Commit 9736754f authored by Maxime's avatar Maxime

multiple twitter accounts: update upload script

parent b26c0b8a
Pipeline #11786 failed with stage
in 1 minute and 3 seconds
import os
from csv import DictReader
from risefor_lobbying.models import Representative, Phone, Email,representativeFunction,commissionPermanente,missionParlementaire,groupeEtude
from risefor_lobbying.models import Representative, TwitterAccount,Phone, Email,representativeFunction,commissionPermanente,missionParlementaire,groupeEtude
from django.core.management.base import BaseCommand
from django.db.models import Value
from django.db.models.functions import Concat
......@@ -194,6 +194,32 @@ class Command(BaseCommand):
email.representative = representative
email.save()
if row["twitter"]:
newTwitter = row["twitter"]
newTwitter = newTwitter.replace("[","")
newTwitter = newTwitter.replace("]","")
newTwitter = newTwitter.replace("'","")
if newTwitter:
if (";" in newTwitter) or ("," in newTwitter):
if ";" in newTwitter:
twitterAccounts = newTwitter.split(";")
if "," in newTwitter:
twitterAccounts = newTwitter.split(",")
for newTwitter in twitterAccounts:
newTwitter = newTwitter.replace(" ","")
newTwitter = newTwitter.replace("-","")
if newTwitter:
twitter = TwitterAccount()
twitter.name = newTwitter
twitter.representative = representative
twitter.save()
else:
twitter = TwitterAccount()
twitter.name = newTwitter
twitter.representative = representative
twitter.save()
#TODO
#handle multiple inputs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment