Example #1
0
File: prepop.py Project: zouf/as2
def prepop_nyc_doh_ratings():
    
    fp = open(settings.DOH_DATASET_LOCATION)

    
    data = json.load(fp,encoding="utf-8")
    #plogger.debug(objs)
    for key in data:
        logger.debug(key)
    #inspdate
    #cuisine
    #name
    #grade
    #score
    #camis
    #address
    #lat
    #violations
    #lng
    pos = 0
    cuisineDict = dict()
    for cid in cuisineCodes:

        cuisineDict[cid] = cuisineLabels[pos]       
        pos += 1
    
    pos = 0
    logger.debug(len(data['name']))
    #15287
    for name in data['name']:
        nm = name
        logger.debug(nm)
        lat = data['lat'][pos]
        lng = data['lng'][pos]
        if data['cuisine'][pos] in cuisineDict:
            restaurant_type= str(cuisineDict[data['cuisine'][pos]])
        else:
            restaurant_type = ''
        grade = str(data['grade'][pos])
        if pos % 400 == 0:
            logger.debug('\n----------')
            logger.debug(nm)

        all_violations= ''
        violationIDs = data['violations'][pos]
        for vid in violationIDs:
            if vid != '' and vid in violationDesc:
                all_violations = all_violations + str(violationDesc[vid])
                all_violations = all_violations + "\n"
        violationPoints = data['score'][pos]
        
        inspdate = format_inspdata(str(data['inspdate'][pos]))
        
        
        (street, borough, zipcode, phone) = parseAddress(data['address'][pos])
        if pos %400 == 0:
            logger.debug('Orig type ID ' + str(data['cuisine'][pos]))
            logger.debug(restaurant_type)
            logger.debug(all_violations)
            logger.debug(str(grade))
            logger.debug(str(violationPoints))
            logger.debug(str( (street, borough, zipcode, phone)))
            logger.debug(inspdate)
            logger.debug('---------------\n')
        b = add_business_server(name=nm,addr=street,state='NY',city=borough,phone=phone,
                    types=[restaurant_type], hours='',wifi=None,serves=None, url='', 
                    average_price=-1,health_letter_code=grade,health_violation_text=all_violations,health_points=int(violationPoints),inspdate=inspdate)
        #override with the loc data from DOH
        b.lat = lat
        b.lon = lng
        b.zipcode = zipcode
        b.save()

        pos += 1
Example #2
0
File: prepop.py Project: zouf/as2
def prepop_businesses(user=get_default_user()):
    print('yo')
    if user == None:
        user = get_default_user()
    reader = csv.reader(open(settings.PREPOP_DIR+'/businesses.csv', 'U'), delimiter=',', quotechar='"')
    i = 0
    indices = {}
    tag_indices ={}
    for row in reader:
        print(row)
        i+=1
        if i == 1:
            bpoint = 0
            for hindex in xrange(0,len(row)):
                if row[hindex] == 'Main':
                    bpoint = hindex
                    break
                indices[row[hindex]] = hindex
            for tindex in xrange(bpoint,len(row)):
                tag_indices[row[tindex]] = tindex
                
            continue
    
        name = row[indices['Business']]
        addr =  row[indices['Address']]
        city =  row[indices['City']]
        state =  row[indices['State']]
        phurl =  row[indices['phurl']]
        types =  row[indices['Types']]
        serves_alcohol = row[ indices['Alcohol']]
        has_wifi =  row[indices['Wifi']]
        average_score =  row[indices['Score']]
        average_price =  row[indices['Price']]
        hours=  row[indices['Hours']]
        phone =  row[indices['Phone']]
        businessURL =  row[indices['URL']]
        
        if has_wifi == 'Yes':
            wifi = True
        else:
            wifi = False
        
        if serves_alcohol == 'Yes':
            serves = True
        else:
            serves = False
    

     
        b = add_business_server(name=name,addr=addr,state=state,city=city,phone=phone,
                            types='', hours=hours,wifi=wifi,serves=serves, url=businessURL, 
                            average_price=average_price)
        
        add_photo_by_url(phurl=phurl,business=b,user=user, default=True,caption="Photo of "+str(b.name), title=str(b.name))

        for t in types.split(','):
            t = t.strip(None)
            if Type.objects.filter(descr=t).count() > 0:
                typeofbus = Type.objects.get(descr=t)
            else:
                typeofbus = Type.objects.create(descr=t,creator=get_default_user(),icon="blankicon.png")
            BusinessType.objects.create(business=b,bustype=typeofbus)    

        for t,rindex in tag_indices.items():    
            topic = Topic.objects.get(descr=t)
            if row[rindex] != '':
                bustopic = add_topic_to_bus(b, topic, user)
                bustopic.content = row[rindex]

                create_article(bustopic,title='Prepopulating ' + str(b.name) + ' ' + str(topic.descr),
                user_message='User ' + str(user) + ' created the article on ' + str(topic),
                content=row[rindex],
                request=None,
                    article_kwargs={'owner': user,
                    'group': None,
                    'group_read': True,
                    'group_write': True,
                    'other_read': True,
                    'other_write':True,
                    }
                )
                bustopic.save()
                logger.debug('Page content: ' + str(bustopic.content))