コード例 #1
0
ファイル: users.py プロジェクト: clemsos/topogram-miner
class UserAPI:

    def __init__(self): 
        print "User API instance"
        # Connect to Mongo
        self.db=MongoDB(db_name).db["users"]
        print "Total users in the db : %d"%self.db.count()
        print '-'*12

        # fetch cities
        here=os.path.dirname(os.path.abspath(__file__))
        provinces_file=os.path.join(here,"cities/provinces.csv")
        self.provinces={}

        with open(provinces_file, 'rb') as csvfile:
            
            provinces_data=csv.reader(csvfile)
            
            for row in provinces_data:
                self.provinces[row[0]]=row[1]


    def create_user(self, data):
        try: 
            province =self.provinces[data[1]]
        except: 
            province=0

        u=User()
        u.uid=data[0]
        u.province=data[1]
        u.gender=data[2]
        u.verified=data[3]
        u.save() # store to mongo
        # print "user %s saved"%data[0]

    def get_user(self,_uid):
        user=self.db.find_one({"uid":_uid}) #.limit(c)
        return user

    def get_province(self,_uid):
        user=self.db.find_one({"uid":_uid}) #.limit(c)
        if user != None:
            return user["province"]
        else : 
            return None
コード例 #2
0
ファイル: users.py プロジェクト: clemsos/mitras
class UserAPI:

    def __init__(self): 
        print "User API instance"
        # Connect to Mongo
        self.db=MongoDB("tweets").db["weibousers"]
        print "Total users in the db : %d"%self.db.count()
        print '-'*12

        # fetch cities
        provinces_file="/home/clemsos/Dev/mitras/lib/cities/provinces.csv"
        self.provinces={}

        with open(provinces_file, 'rb') as csvfile:
            
            provinces_data=csv.reader(csvfile)
            
            for row in provinces_data:
                self.provinces[row[0]]=row[1]


    def create_user(self, data):
        try: 
            province =self.provinces[data[1]]
        except: 
            province=0

        u=User()
        u.uid=data[0]
        u.province=data[1]
        u.gender=data[2]
        u.verified=data[3]
        u.save() # store to mongo
        # print "user %s saved"%data[0]

    def get_user(self,_uid):
        user=self.db.find_one({"uid":_uid}) #.limit(c)
        return user

    def get_province(self,_uid):
        user=self.db.find_one({"uid":_uid}) #.limit(c)
        if user != None:
            return user["province"]
        else : 
            return None
コード例 #3
0
class UserAPI:
    def __init__(self):
        print "User API instance"
        # Connect to Mongo
        self.db = MongoDB(db_name).db["users"]
        print "Total users in the db : %d" % self.db.count()
        print '-' * 12

        # fetch cities
        here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        provinces_file = os.path.join(here, "data/provinces.csv")
        self.provinces = {}

        with open(provinces_file, 'rb') as csvfile:

            provinces_data = csv.reader(csvfile)

            for row in provinces_data:
                self.provinces[row[0]] = row[1]

    def create_user(self, data):
        try:
            province = self.provinces[data[1]]
        except:
            province = 0

        u = User()
        u.uid = data[0]
        u.province = data[1]
        u.gender = data[2]
        u.verified = data[3]
        u.save()  # store to mongo
        # print "user %s saved"%data[0]

    def get_user(self, _uid):
        user = self.db.find_one({"uid": _uid})  #.limit(c)
        return user

    def get_province(self, _uid):
        user = self.db.find_one({"uid": _uid})  #.limit(c)
        if user != None:
            return user["province"]
        else:
            return None