Exemplo 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()
Exemplo 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))
Exemplo n.º 3
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')
Exemplo n.º 4
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)