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()
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))
def main(): # COVID 19 with open('campaigns.json') as json_file: data2 = json.load(json_file) campaigns = data2['campaigns'] print() print() print('Campaigns:') print() for camp in campaigns: dbcamp = Campaign() dbcamp.id = camp['id'] dbcamp.url = camp['url'] dbcamp.category_id = camp['category_id'] dbcamp.category = camp['category'] dbcamp.currencycode = camp['currencycode'] dbcamp.current_amount = camp['current_amount'] dbcamp.goal = camp['goal'] dbcamp.donators = camp['donators'] dbcamp.days_active = camp['days_active'] dbcamp.title = camp['title'] dbcamp.description = camp['description'] dbcamp.has_beneficiary = camp['has_beneficiary'] dbcamp.turn_off_donations = camp['turn_off_donations'] dbcamp.user_id = camp['user_id'] dbcamp.user_first_name = camp['user_first_name'] dbcamp.user_last_name = camp['user_last_name'] dbcamp.user_profile_url = camp['user_profile_url'] dbcamp.deactivated = camp['deactivated'] dbcamp.campaign_image_url = camp['campaign_image_url'] dbcamp.launch_date = camp['launch_date'] dbcamp.campaign_hearts = camp['campaign_hearts'] dbcamp.social_share_total = camp['social_share_total'] dbcamp.social_share_last_update = camp['social_share_last_update'] dbcamp.location_city = camp['location_city'] dbcamp.location_country = camp['location_country'] dbcamp.location_zip = camp['location_zip'] dbcamp.charity_valid = camp['charity_valid'] dbcamp.charity_npo_id = camp['charity_npo_id'] dbcamp.charity_name = camp['charity_name'] dbcamp.is_fulfilled_numeric = camp['is_fulfilled_numeric'] dbcamp.percent_fulfilled = camp['percent_fulfilled'] dbcamp.success = camp['success'] dbcamp.ranking = camp['ranking'] dbcamp.save() print('Complete')
def main(): import csv import json if len(Campaign.objects.all()) == 0: with open('campaigns.json') as json_file: data = json.load(json_file) campaigns = data id = 0 for p in campaigns: theCamp = Campaign() theCamp.currencycode = campaigns[p]['currencycode'] theCamp.current_amount = campaigns[p]['current_amount'] theCamp.goal = campaigns[p]['goal'] theCamp.auto_fb_post_mode = campaigns[p]['auto_fb_post_mode'] theCamp.donators = campaigns[p]['donators'] theCamp.days_active = campaigns[p]['days_active'] theCamp.title = campaigns[p]['title'] theCamp.description = campaigns[p]['description'] theCamp.has_beneficiary = campaigns[p]['has_beneficiary'] theCamp.status = campaigns[p]['status'] theCamp.deactivated = campaigns[p]['deactivated'] theCamp.campaign_hearts = campaigns[p]['campaign_hearts'] theCamp.social_share_total = campaigns[p]['social_share_total'] theCamp.location_country = campaigns[p]['location_country'] theCamp.is_charity = campaigns[p]['is_charity'] theCamp.charity_valid = campaigns[p]['charity_valid'] if campaigns[p]['donators'] != '0': avg_donation = round((int(campaigns[p]['current_amount']) / int(campaigns[p]['donators'])), 2) theCamp.avg_donation = avg_donation else: avg_donation = 0 theCamp.avg_donation = avg_donation theScore = 0 if int(campaigns[p]['donators']) < 2: theScore += 0 elif int(campaigns[p]['donators']) < 10: theScore += 0.5 elif int(campaigns[p]['donators']) < 25: theScore += 1 elif int(campaigns[p]['donators']) < 50: theScore += 1.5 elif int(campaigns[p]['donators']) < 100: theScore += 2 elif int(campaigns[p]['donators']) < 200: theScore += 2.5 elif int(campaigns[p]['donators']) < 500: theScore += 3 elif int(campaigns[p]['donators']) < 1000: theScore += 3.5 elif int(campaigns[p]['donators']) < 2000: theScore += 4 elif int(campaigns[p]['donators']) < 10000: theScore += 4.5 elif int(campaigns[p]['donators']) > 10000: theScore += 5 if int(avg_donation) < 5: theScore += 0 elif int(avg_donation) < 10: theScore += 0.5 elif int(avg_donation) < 15: theScore += 1 elif int(avg_donation) < 20: theScore += 1.5 elif int(avg_donation) < 30: theScore += 2 elif int(avg_donation) < 50: theScore += 2.5 elif int(avg_donation) < 75: theScore += 3 elif int(avg_donation) < 125: theScore += 3.5 elif int(avg_donation) < 200: theScore += 4 elif int(avg_donation) < 500: theScore += 4.5 elif int(avg_donation) > 500: theScore += 5 theCamp.c_rating = theScore theCamp.save() print(p, theScore) else: print('Already Loaded')