Esempio n. 1
0
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()
Esempio n. 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))
Esempio n. 3
0
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')
Esempio n. 4
0
def main():
    num = 0
    Campaign.objects.all().delete()
    Score.objects.all().delete()

    #create objects and store them in database
    with open('campaigns.json', encoding='utf-8') as json_file:
        data = json.load(json_file)
    campaigns = data['campaigns']
    for camp in campaigns:
        #if num % 3 == 0:
        dbcamp = Campaign()
        dbcamp.url = camp['url']
        dbcamp.campaign_id = int(camp['campaign_id'])
        dbcamp.category = camp['goal']
        dbcamp.goal = int(camp['goal'])
        dbcamp.current_amount = int(camp['current_amount'])
        dbcamp.currency_code = camp['currencycode']
        dbcamp.donators = int(camp['donators'])
        dbcamp.days_active = int(camp['days_active'])
        dbcamp.days_created = int(camp['days_created'])
        dbcamp.title = camp['title']
        dbcamp.description = camp['description']
        dbcamp.user_first_name = camp['user_first_name']
        dbcamp.user_last_name = camp['user_last_name']

        if camp['visible_in_search'] == 'TRUE':
            dbcamp.visible_in_search = 'True'
        else:
            dbcamp.visible_in_search = 'False'

        if camp['deactivated'] == 'TRUE':
            dbcamp.deactivated = 'True'
        else:
            dbcamp.deactivated = 'False'

        if camp['is_launched'] == 'TRUE':
            dbcamp.is_launched = 'True'
        else:
            dbcamp.is_launched = 'False'

        dbcamp.campaign_image_url = camp['campaign_image_url']
        dbcamp.launch_date = camp['launch_date']
        dbcamp.campaign_hearts = int(camp['campaign_hearts'])
        dbcamp.social_share_total = int(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']

        if camp['is_charity'] == 'TRUE':
            dbcamp.is_charity = 'True'
        elif camp['is_charity'] == 'FALSE':
            dbcamp.is_charity = 'False'

        dbcamp.charity_name = camp['charity_name']
        num = num + 1
        dbcamp.save()

    print(num)
    print('campaigns saved successfully')

    num = 0

    with open('scores.json', encoding='utf-8') as json_file:
        data = json.load(json_file)
    scores = data['scores']
    for sco in scores:
        dbsco = Score()
        dbsco.campaign_id = sco['campaign_id']
        dbsco.score = int(sco['Score'])
        dbsco.rating = sco['Rating']
        num = num + 1
        dbsco.save()

    print(num)
    print('updates saved')
def createCampaigns():
    with open('Clean_Camp7_URL.csv', encoding='utf-8') as campCSV:
        data = csv.reader(campCSV, delimiter=',')
        
        # integer variables to access them in the rows (what array index are they stored at?)
        category = 7
        currentAmount = 9
        goal = 10
        donators = 11
        daysActive = 12
        title = 14
        description = 15
        userFirst = 20
        userLast = 21
        status = 24
        imageUrl = 26
        launchDate = 28
        campaignHearts = 29
        socialShareTotal = 30
        locationCity = 31
        locationCountry = 32
        percentComplete = 36
        percentCompleteForGivenDays = 37
        moneyPerDonor = 38
        quality = 55
        locationState = 56

        # number of rows that were unable to save to the database
        numFails = 0

        for row in data:
            if(row[1] != 'Unnamed: 0'): # this skips the first row, we don't want to save the headers to our database
                dbcamp = Campaign()
                dbcamp.category = row[category]
                dbcamp.currentAmount = Decimal(row[currentAmount])
                dbcamp.daysActive = Decimal(row[daysActive])
                dbcamp.goal = row[goal]
                dbcamp.donators = row[donators]
                dbcamp.title = row[title]
                dbcamp.description = row[description]
                dbcamp.userFirst = row[userFirst]
                dbcamp.userLast = row[userLast]
                dbcamp.status = row[status] # if = 1 then true, if = 0 then false // I hope :)
                dbcamp.imageUrl = row[imageUrl]
                dbcamp.launchDate = row[launchDate]
                dbcamp.campaignHearts = row[campaignHearts]
                dbcamp.socialShareTotal = row[socialShareTotal]
                dbcamp.percentComplete = row[percentComplete]
                dbcamp.locationCity = row[locationCity]
                dbcamp.locationCountry = row[locationCountry]
                dbcamp.locationState = row[locationState]
                if dbcamp.percentComplete == 'Infinity':
                    print('percent complete = infinity error')
                    dbcamp.percentComplete = 0.0
                dbcamp.percentCompleteForGivenDays = row[percentCompleteForGivenDays]
                if dbcamp.percentCompleteForGivenDays == 'Infinity':
                    print('percent complete for given days = infinity error')
                    dbcamp.percentCompleteForGivenDays = 0.0
                dbcamp.moneyPerDonor = row[moneyPerDonor]
                if dbcamp.moneyPerDonor == 'Infinity':
                    print('money Per Donor = infinity error')
                    dbcamp.moneyPerDonor = 0.0
                dbcamp.quality = row[quality]

                try:
                    dbcamp.save()
                except ValueError as err:
                    print("VALUE error saving", dbcamp.title, "--- to database")
                    numFails += 1
                except TypeError as err:
                    print("TYPE error saving", dbcamp.title, "--- to database")
                    numFails += 1
                except IOError as err:
                    print("I/O error saving", dbcamp.title, "--- to database")
                    numFails += 1

                # print(dbcamp)
            #end of if statement
        print("finished saving campaigns to the database")
        print("how many records failed to save?", numFails)
Esempio n. 6
0
def main():

    print('start script')
    # read the json data
    with open('data.json', encoding="utf8") as json_data:
        data = json.load(json_data)
        print("opens")
    cats = {}
    concur = {}
    y = 1
    i = 1

    # find the categories, and replace them with the
    # new category id (created below)
    for prod in data:
        if prod['category'] not in cats:
            cats[prod['category']] = i
            i += 1
        if prod['currencycode'] not in concur:
            concur[prod['currencycode']] = y
            y += 1
        prod['category'] = cats[prod['category']]
        prod['currencycode'] = concur[prod['currencycode']]
    # create the categories

    for cat_name, cat_id in cats.items():
        new_cat = Category()
        new_cat.id = cat_id
        new_cat.title = cat_name
        new_cat.save()

    for concur_code, curr_id in concur.items():
        new_code = CurrencyCode()
        new_code.id = curr_id
        new_code.code = concur_code
        new_code.save()
    # create the products
    for prod in data:
        p = Campaign()
        p.url = prod['url']
        p.campaign_id = prod['campaign_id']
        if prod['auto_fb_post_mode'] == 1:
            p.auto_fb_post_mode = True
        else:
            p.auto_fb_post_mode = False
        p.current_amount = prod['current_amount']
        p.category = Category.objects.get(id=prod['category'])
        p.currencycode = CurrencyCode.objects.get(id=prod['currencycode'])
        p.donators = prod['donators']

        if isinstance(prod['days_active'], int):
            p.days_active = prod['days_active']
        else:
            p.days_active = 0
        p.title = prod['title']
        p.description = prod['description']
        p.default_url = prod['default_url']
        if prod['has_beneficiary'] == 1:
            p.has_beneficiary = True
        else:
            p.has_beneficiary = False
        if prod['turn_off_donations'] == 1:
            p.turn_off_donations = True
        else:
            p.turn_off_donations = False
        if prod['visible_in_search'] == 1:
            p.visible_in_search = True
        else:
            p.visible_in_search = False
        if prod['status'] == 1:
            p.status = True
        else:
            p.status = False
        if prod['deactivated'] == 1:
            p.deactivated = True
        else:
            p.deactivated = False
        if prod['state'] == 1:
            p.state = True
        else:
            p.state = False
        p.campaign_image_url = prod['campaign_image_url']
        if p.launch_date == '':
            prod['launch_date'] = '1970-01-01'
        p.launch_date = prod['launch_date']
        p.campaign_hearts = prod['campaign_hearts']
        p.social_share_total = prod['social_share_total']
        if p.social_share_last_update == '':
            prod['social_share_last_update'] = '1970-01-01'
        p.social_share_last_update = prod['social_share_last_update']
        p.location_city = prod['location_city']
        p.location_country = prod['location_country']
        if prod['location_zip'] == '':
            prod['location_zip'] = 0
        p.location_zip = prod['location_zip']
        if prod['is_charity'] == 1:
            p.is_charity = True
        else:
            p.is_charity = False
        p.charity_name = prod['charity_name']
        p.riskScore = prod['riskScore']
        p.riskScoreQuartile = prod['riskScoreQuartile']
        p.save()
        print('saved')
Esempio n. 7
0
    def post(self, request, format=None):
        prod = request.data
        p = Campaign()
        p.url = prod['url']
        p.campaign_id = prod['campaign_id']
        if prod['auto_fb_post_mode'] == 1:
            p.auto_fb_post_mode = True
        else:
            p.auto_fb_post_mode = False
        p.current_amount = prod['current_amount']
        p.category = Category.objects.get(title=prod['category'])
        p.currencycode = CurrencyCode.objects.get(code=prod['currencycode'])
        p.donators = prod['donators']

        if isinstance(prod['days_active'], int):
            p.days_active = prod['days_active']
        else:
            p.days_active = 0
        p.title = prod['title']
        p.description = prod['description']
        p.default_url = prod['default_url']
        if prod['has_beneficiary'] == 1:
            p.has_beneficiary = True
        else:
            p.has_beneficiary = False
        if prod['turn_off_donations'] == 1:
            p.turn_off_donations = True
        else:
            p.turn_off_donations = False
        if prod['visible_in_search'] == 1:
            p.visible_in_search = True
        else:
            p.visible_in_search = False
        if prod['status'] == 1:
            p.status = True
        else:
            p.status = False
        if prod['deactivated'] == 1:
            p.deactivated = True
        else:
            p.deactivated = False
        if prod['state'] == 1:
            p.state = True
        else:
            p.state = False
        p.campaign_image_url = prod['campaign_image_url']
        if p.launch_date == '':
            prod['launch_date'] = '1970-01-01'
        p.launch_date = prod['launch_date']
        p.campaign_hearts = prod['campaign_hearts']
        p.social_share_total = prod['social_share_total']
        if p.social_share_last_update == '':
            prod['social_share_last_update'] = '1970-01-01'
        p.social_share_last_update = prod['social_share_last_update']
        p.location_city = prod['location_city']
        p.location_country = prod['location_country']
        if prod['location_zip'] == '':
            prod['location_zip'] = 0
        p.location_zip = prod['location_zip']
        if prod['is_charity'] == 1:
            p.is_charity = True
        else:
            p.is_charity = False
        p.charity_name = prod['charity_name']
        #p.save()
        return Response({"Created"}, status=status.HTTP_201_CREATED)