def main():
    # Copy campaigns
    with open('campaigns_for_management.csv', newline='',
              encoding="utf8") as f:
        reader = csv.reader(f)
        campaigns = list(reader)
        for item in campaigns:
            if item[1] != "url":
                campaign = Campaign()
                campaign.url = item[1]
                campaign.campaign_id = item[2]
                campaign.auto_fb_post_mode = item[3]
                campaign.collected_date = item[4]
                campaign.category_id = item[5]
                campaign.category = item[6]
                campaign.currencycode = item[7]
                campaign.current_amount = item[8]
                campaign.goal = item[9]
                campaign.donators = item[10]
                campaign.days_active = item[11]
                campaign.days_created = item[12]
                campaign.title = item[13]
                campaign.description = item[14]
                campaign.default_url = item[15]
                campaign.has_beneficiary = item[16]
                campaign.media_type = item[17]
                campaign.project_type = item[18]
                campaign.turn_off_donations = item[19]
                campaign.user_id = item[20]
                campaign.user_first_name = item[21]
                campaign.user_last_name = item[22]
                campaign.user_facebook_id = item[23]
                campaign.user_profile_url = item[24]
                campaign.visible_in_search = item[25]
                campaign.status = item[26]
                campaign.deactivated = item[27]
                campaign.state = item[28]
                campaign.is_launched = item[29]
                campaign.campaign_image_url = item[30]
                campaign.created_at = item[31]
                campaign.launch_date = item[32]
                campaign.campaign_hearts = item[33]
                campaign.social_share_total = item[34]
                campaign.social_share_last_udpate = item[35]
                campaign.location_city = item[36]
                campaign.location_country = item[37]
                campaign.location_zip = item[38]
                campaign.is_charity = item[39]
                campaign.charity_valid = item[40]
                campaign.charity_npo_id = item[41]
                campaign.charity_name = item[42]
                campaign.velocity = item[43]
                campaign.overall_popularity = item[44]
                campaign.percent_goal_complete = item[45]
                campaign.avg_donation_per_donor = item[46]

                print(campaign)

                campaign.save()
Beispiel #2
0
def main():
    with open("campaigns.csv", mode="r", encoding="utf-8-sig") as read_file:
        campaignData = csv.DictReader(read_file)
        print('CAMPAIGNS')
        for camp in campaignData:
            dbcamp = Campaign()
            dbcamp.url = str(camp['url'])
            dbcamp.campaign_id = str(camp['campaign_id'])
            dbcamp.auto_fb_post_mode = str(camp['auto_fb_post_mode'])
            dbcamp.collected_date = str(camp['collected_date'])
            dbcamp.category_id = str(camp['category_id'])
            dbcamp.category = str(camp['category'])
            dbcamp.currencycode = str(camp['currencycode'])
            dbcamp.current_amount = str(camp['current_amount'])
            dbcamp.goal = str(camp['goal'])
            dbcamp.donators = str(camp['donators'])
            dbcamp.days_active = str(camp['days_active'])
            dbcamp.days_created = str(camp['days_created'])
            dbcamp.title = str(camp['title'])
            dbcamp.description = str(camp['description'])
            dbcamp.default_url = str(camp['default_url'])
            dbcamp.has_beneficiary = str(camp['has_beneficiary'])
            dbcamp.media_type = str(camp['media_type'])
            dbcamp.project_type = str(camp['project_type'])
            dbcamp.turn_off_donations = str(camp['turn_off_donations'])
            dbcamp.user_id = str(camp['user_id'])
            dbcamp.user_first_name = str(camp['user_first_name'])
            dbcamp.user_last_name = str(camp['user_last_name'])
            dbcamp.user_facebook_id = str(camp['user_facebook_id'])
            dbcamp.user_profile_url = str(camp['user_profile_url'])
            dbcamp.visible_in_search = str(camp['visible_in_search'])
            dbcamp.status = str(camp['status'])
            dbcamp.deactivated = str(camp['deactivated'])
            dbcamp.state = str(camp['state'])
            dbcamp.is_launched = str(camp['is_launched'])
            dbcamp.campaign_image_url = str(camp['campaign_image_url'])
            dbcamp.created_at = str(camp['created_at'])
            dbcamp.launch_date = str(camp['launch_date'])
            dbcamp.campaign_hearts = str(camp['campaign_hearts'])
            dbcamp.social_share_total = str(camp['social_share_total'])
            dbcamp.social_share_last_update = str(
                camp['social_share_last_update'])
            dbcamp.location_city = str(camp['location_city'])
            dbcamp.location_country = str(camp['location_country'])
            dbcamp.location_zip = str(camp['location_zip'])
            dbcamp.is_charity = str(camp['is_charity'])
            dbcamp.charity_valid = str(camp['charity_valid'])
            dbcamp.charity_npo_id = str(camp['charity_npo_id'])
            dbcamp.charity_name = str(camp['charity_name'])
            dbcamp.velocity = str(camp['velocity'])
            dbcamp.save()
            print(str(dbcamp.url))