Commits

David Xie  committed 03b1aff

fix a little problem for importing stores

  • Participants
  • Parent commits ef84468

Comments (0)

Files changed (1)

     """
     csv file format:
     [0]No, [1]Mall Name, [2]Address1, [3]Address2, [4]City,
-        [5]State, [6]Zipcode, [7]Mall Map, [8]Store Name, [9]Location, [10]Phone
+    [5]State, [6]Zipcode, [7]Mall Map, [8]Store Name, [9]Location, [10]Phone
     """
     timeStamp = int(time.time())
     reader = csv.reader(open('temp.csv'))
     reader.next()
     for row in reader:
-        malls = list(db.select('malls', where="name=$name",
-            vars={'name':row[1].strip()}))
-        if len(malls) == 0:
-            states = list(db.select('states',
-                where="LOWER(state)=$state",
-                vars={'state':row[5].strip().lower()}))
-            if len(states) > 0:
-                stateId = states[0].id
+        if row[8].strip() is not None:
+            malls = list(db.select('malls', where="name=$name",
+                vars={'name':row[1].strip()}))
+            if len(malls) == 0:
+                states = list(db.select('states',
+                    where="LOWER(state)=$state",
+                    vars={'state':row[5].strip().lower()}))
+                if len(states) > 0:
+                    stateId = states[0].id
+                else:
+                    stateId = 0
+                cities = list(db.select('cities',
+                    where="LOWER(city)=$city",
+                    vars={'city':row[4].strip().lower()}))
+                if len(cities) > 0:
+                    cityId = cities[0].id
+                else:
+                    cityId = 0
+                mallId = db.insert('malls', name=row[1].strip(),
+                            address1=row[2].strip(),
+                            address2=row[3].strip(),
+                            cityId=cityId,
+                            stateId=stateId,
+                            zipcode=row[6].strip(),
+                            phone=' ',
+                            created_time=timeStamp,
+                            modified_time=timeStamp,
+                            mallmap=row[7]
+                        )
             else:
-                stateId = 0
-            cities = list(db.select('cities',
-                where="LOWER(city)=$city",
-                vars={'city':row[4].strip().lower()}))
-            if len(cities) > 0:
-                cityId = cities[0].id
-            else:
-                cityId = 0
-            mallId = db.insert('malls', name=row[1].strip(),
-                        address1=row[2].strip(),
-                        address2=row[3].strip(),
-                        cityId=cityId,
-                        stateId=stateId,
-                        zipcode=row[6].strip(),
-                        phone=' ',
-                        created_time=timeStamp,
-                        modified_time=timeStamp,
-                        mallmap=row[7]
-                    )
-        else:
-            mallId = malls[0].id
+                mallId = malls[0].id
 
-        stores = list(db.select('stores',
-            where="name=$name AND mallId=$mallId",
-            vars={'name':row[8].strip(),'mallId':mallId}))
-        if len(stores) == 0:
-            db.insert('stores',
-                        mallId=mallId,
-                        name=row[8].strip(),
-                        address=row[9].strip(),
-                        phone=row[10].strip(),
-                        description='',
-                        created_time=timeStamp
-                    )
+            stores = list(db.select('stores',
+                where="name=$name AND mallId=$mallId",
+                vars={'name':row[8].strip(),'mallId':mallId}))
+            if len(stores) == 0:
+                db.insert('stores',
+                            mallId=mallId,
+                            name=row[8].strip(),
+                            address=row[9].strip(),
+                            phone=row[10].strip(),
+                            description='',
+                            created_time=timeStamp
+                        )
 
 admin_app = web.application(urls, globals(), autoreload = True)
 admin_app.add_processor(web.loadhook(my_loadhook))