Example #1
0
def get_imgs(num):
    local_db = db.get_local_db('blue')
    cursor = local_db.cursor()
    img_sql = '''select url, tiny_url from fake_user where num = %d ''' % num
    cursor.execute(img_sql)
    imgs = cursor.fetchall()
    return imgs
Example #2
0
def get_ticket(user_id):
    blue_db = db.get_local_db('blue')
    cursor = blue_db.cursor()
    sql = ''' select ticket from user_passport where user_id = %d ''' % user_id
    cursor.execute(sql)
    ticket = cursor.fetchone()
    return ticket
    def update_db_device_status(self):
        """Override this to change database storage behavior"""
        device_status = DeviceStatus(self.node)
        device_status = DeviceSchema().dump(device_status)

        _logger.debug(device_status)
        db_id = device_status["_id"]

        # Update local DB
        with get_local_db() as db:
            if db_id in db:
                # Update item if it exists
                local_db_doc = db[db_id]

                # Don't do any database updates if the value has not changed
                if local_db_doc["value"] != device_status["value"]:
                    local_db_doc.update(device_status)
                    local_db_doc.save()

            else:
                # Create item if it doesn't exist
                local_db_doc = db.create_document(device_status)

        # Update AWS DB
        aws_table = get_aws_table()
        try:
            # Update item if it exists
            current_doc = aws_table.get(db_id)
            if current_doc.value != device_status["value"]:
                actions = [
                    # name should never change
                    # aws_table.name.set(device_status["name"]),
                    aws_table.value.set(device_status["value"]),
                    aws_table.year.set(device_status["year"]),
                    aws_table.month.set(device_status["month"]),
                    aws_table.day.set(device_status["day"]),
                    aws_table.hour.set(device_status["hour"]),
                    aws_table.minute.set(device_status["minute"]),
                    aws_table.microsecond.set(device_status["microsecond"])
                ]
                current_doc.update(actions=actions)
        except aws_table.DoesNotExist:
            # Create item if it doesn't exist
            new_doc = dict(**device_status)
            new_doc.pop("_id")
            item = aws_table(db_id, **new_doc)
            item.save()

        return local_db_doc
Example #4
0
def main():
    ticket = get_ticket(2256)

    local_db = db.get_local_db('blue')
    cursor = local_db.cursor()

    start = 1
    end = 50
    while start <= end:
        try:
            index = 1
            while True:
                file_path = '''/Users/omar/Downloads/头像2/%d/%s.jpg''' % (start, str(start) + ' (' + str(index) + ')')
                if os.path.isfile(file_path):
                    img_file = open(file_path, 'rb')
                    upload(start, index, ticket, img_file, cursor)
                    index += 1
                    time.sleep(5)
                else:
                    break

        except Exception, e:
            print ' Exception:', e
        start += 1