Exemplo n.º 1
0
    def insert(self,d):
        n = MySQL()

        n.selectDb('joke')
        tbname = 'joke'
        n.insert(tbname, d)
        n.commit()
Exemplo n.º 2
0
    def insert(self,d):
        n = MySQL()

        n.selectDb('images')
        tbname = 'similar_images'
        n.insert(tbname, d)
        n.commit()
Exemplo n.º 3
0
 def addViewCount(self,id):
     n = MySQL()
     n.selectDb('joke')
     tbname = 'joke'
     sql = "update {0} set view_count = view_count+1".format(tbname)
     n.query(sql)
     # n.update(tbname, { 'view_count': "view_count+1"}, "id='"+id+"'")
     n.commit()
Exemplo n.º 4
0
def insert_data(data):
	n=MySQL()
	sql = "select id from urls_crawled where url='"+data['url']+"';"
	result = n.query(sql)
	if result == 0:
		try:
			n.insert('urls_crawled',data)
		except:
			return 200
	n.commit()
Exemplo n.º 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.path.insert(0, 'lib')
from mysql import MySQL

import ConfigParser
import logging

config = ConfigParser.ConfigParser()
config.read('config/config.cfg')

db_config = config._sections['db']
db_config.pop('__name__')

a = MySQL(**db_config)

# sql = "show tables"
sql = "insert into url (post_id, url, status) values ('11', 'http://www.baidu.com', '0')"
a.query(sql)
a.commit()

# aa = a.get_all(sql)
# print aa

Exemplo n.º 6
0
 def updateJoke(self,content,id):
     n = MySQL()
     n.selectDb('joke')
     tbname = 'joke'
     n.update(tbname, { 'content': content}, "id='"+id+"'")
     n.commit()
Exemplo n.º 7
0
    favorite_1=row['favorite_count']
    print "status:"+status_id_1
    print "retweet:"+retweet_1
    print "favorite:"+favorite_1
    sql_check_1="select * from popularity where status_id='%s'"%(status_id_1)
    check_1=myconn.query(sql_check_1)
    res_1=myconn.fetchAll()
    for i in res_1:
        myretweet_1=i['retweet']
        myfavorite_1=i['favorite']
    if check_1>0: 
            if int(retweet_1) > int(myretweet_1) or int(myfavorite_1)>int(favorite_1) :
                sql_up_1="update popularity set retweet = '%s',favorite ='%s' where status_id ='%s'"%(myretweet_1,myfavorite_1,status_id_1)
                try:
                    myconn.query(sql_up_1)
                    myconn.commit()
                    print sql_up_1+"success"
                except:
                    myconn.rollback()
                    print sql_up_1+"fail"
    else:
        sql_ins_1="insert into popularity(status_id,retweet,favorite) values('%s','%s','%s')"%(status_id_1,retweet_1,favorite_1)
        try:
            myconn.query(sql_ins_1)
            myconn.commit()
            print sql_ins_1+"success"
        except:
            myconn.rollback()
            print sql_ins_1+"fail"
    
print "set popularity finished"