def login(self): print('####登录后台中####') token4 = '{}/admin/login.php?referer={}%2Fadmin%2F'.format( self.base_url, url_encode(self.base_url)) token = md5(self.token1 + '&' + token4) url = self.base_url + '/index.php/action/login?_=%s' % token data = { 'name': 'admin', 'password': '******', 'referer': '{}%2Fadmin%2F'.format(url_encode(self.base_url)) } headers = { 'User-Agent': self.user_agent, 'Referer': token4, } self.session.post(url, data, headers=headers) self.session_login = copy.deepcopy(self.session) print('Cookies:', self.session.cookies.get_dict()) ''' 啊啊啊,之前把获取authCode的语句放在了init里面,但是实际上每次登录, authCode都会改变,所以每次使用的都是上一次的authCode,因而token永远都是旧的, 一直302跳转至write-page界面,好几个小时才从数据库中发现这个错误 ''' db = PyMySQL.DB(self.ip, self.user, self.password, self.database) self.token2 = str(db.user_authCode) self.token3 = str(db.user_uid)
def cal_mammut_task(cur_day, task_type): mm_db = PyMySQL.connect("eadb10-writer", "mammut", "n7ZaNi8J6BADgJ1q", "mm_azkaban_eadhadoop", charset='utf8') mm_cursor = mm_db.cursor() mm_cursor.execute("set names utf8mb4") mm_cursor.execute(""" SELECT from_unixtime(start_time/1000, '%Y-%m-%d') AS etl_day, from_unixtime(start_time/1000, '%H:%i:%s') AS submit_time, from_unixtime(end_time/1000, '%H:%i:%s') AS produced_time, (end_time/1000-CAST(end_time/1000/3600/24 AS signed)*24*3600-3600)/60 AS late_mins, -- 本应该是-9*3600,因为8小时时差,所以+8*3600--合并为-》-3600 CASE WHEN status = 50 THEN 'SUCCESS' WHEN status = 60 THEN 'ABORTED' ELSE 'FAILURE' END AS status FROM mm_azkaban_eadhadoop.execution_flows WHERE flow_id = '{}' AND from_unixtime(start_time/1000, '%Y-%m-%d')='{}' AND from_unixtime(start_time/1000, '%Y-%m-%d')=from_unixtime(end_time/1000, '%Y-%m-%d') ORDER BY start_time;""".format(task_name, cur_day)) mm_results = mm_cursor.fetchall() res = [] for mm_result in mm_results: etl_day = mm_result[0] submit_time = mm_result[1] produced_time = mm_result[2] late_mins = float(mm_result[3]) if float(mm_result[3]) > 0 else 0 status = mm_result[4] res.append((etl_day, submit_time, produced_time, late_mins, status)) if status == 'SUCCESS': break return res
def cal_azk_job_task(cur_day, task_name): azk_db = PyMySQL.connect("analysis-db", "azkaban_secure", "azkaban_secure", "azkaban_secure", charset='utf8') azk_cursor = azk_db.cursor() azk_cursor.execute(""" SELECT from_unixtime(start_time/1000, '%Y-%m-%d') AS etl_day, from_unixtime(start_time/1000, '%H:%i:%s') AS submit_time, from_unixtime(end_time/1000, '%H:%i:%s') AS produced_time, (end_time/1000-CAST(end_time/1000/3600/24 AS signed)*24*3600-3600)/60 AS late_mins, -- 本应该是-9*3600,因为8小时时差,所以+8*3600--合并为-》-3600 CASE WHEN status = 50 THEN 'SUCCESS' WHEN status = 60 THEN 'ABORTED' ELSE 'FAILURE' END AS status FROM azkaban_secure.execution_jobs WHERE job_id LIKE '%{}%' AND from_unixtime(start_time/1000, '%Y-%m-%d')='{}' AND from_unixtime(start_time/1000, '%Y-%m-%d')=from_unixtime(end_time/1000, '%Y-%m-%d') ORDER BY start_time;""".format(task_name, cur_day)) azk_results = azk_cursor.fetchall() res = [] for azk_result in azk_results: etl_day = azk_result[0] submit_time = azk_result[1] produced_time = azk_result[2] late_mins = float(azk_result[3]) if float(azk_result[3]) > 0 else 0 status = azk_result[4] res.append((etl_day, submit_time, produced_time, late_mins, status)) if status == 'SUCCESS': break return res
def new_request_subscriber(event): request = event.request settings = request.registry.settings settings['db'] = PyMySQL.connect(host="localhost", user="******", passwd="root", db="local") request.db = settings['db'] request.db_cursor = request.db.cursor() request.add_finished_callback(close_db_connection)
def Log_in(*args): e_code = i_code.get() e_name = i_name.get() db = database.connect('127.0.0.1', 'root', 'root', 'kytsyk_d') cursor = db.cursor() cursor.execute(f"SELECT Login, Password FROM new_table WHERE Login = '******' AND Password = '******'") if cursor.fetchone() is None: TakNi() else: Dialog() db.close()
def setUp(self): self._db = PyMySQL.connect(host="localhost", user="******", passwd="root", db="local") self._db_cursor = self._db.cursor() self._restore_database() self._browser = webdriver.Remote( command_executor='http://yalla.dev:4444/wd/hub', desired_capabilities=DesiredCapabilities.FIREFOX )
def count_azk_flow_task(cur_day, task_name): azk_db = PyMySQL.connect("analysis-db", "azkaban_secure", "azkaban_secure", "azkaban_secure", charset='utf8') azk_cursor = azk_db.cursor() azk_cursor.execute( "SELECT COUNT(job_id) FROM execution_jobs WHERE flow_id LIKE 'FINAL_{}_{}_%';" .format(cur_day, task_name)) azk_result = azk_cursor.fetchone() return int(azk_result[0])
def reg(*args): e_code = i_code.get() e_name = i_name.get() e_price = i_price.get() Lowroot = database.connect('127.0.0.1', 'root', 'root', 'kytsyk_d') cursor = Lowroot.cursor() cursor.execute("INSERT INTO new_table(Login, Password, UserName) VALUES(%s, %s, %s)", (e_code, e_name, e_price)) Lowroot.commit() Zareg() Dialog() Lowroot.close()
def mysqlInsert( name, text, createdTime): db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. insertQueryStr = "insert into <tablename> (<Column names>) values ('" + name +"','"+ text+"','"+ createdTime +"' )" cursor.execute(insertQueryStr) # Fetch a single row using fetchone() method. #data = cursor.fetchone() print ("Database query : "+ insertQueryStr) # disconnect from server db.close()
def store_data(created_at, text, screen_name, tweet_id): db = PyMySQL.connect(host="myweb.cs.uwindsor.ca/gupta13b_TwitterHandler", user="******", passwd="12345", db=gupta13b_TwitterHandler, charset="utf8") cursor = db.cursor() insert_query = "INSERT INTO twitter (tweet_id, screen_name, created_at, text) VALUES (%s, %s, %s, %s)" cursor.execute(insert_query, (tweet_id, screen_name, created_at, text)) db.commit() cursor.close() db.close() return
def btn_s1(self): db = PyMySQL.connect("localhost", "root", "root123", "MockExam") # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("SELECT VERSION()") # Fetch a single row using fetchone() method. data = cursor.fetchone() print("Database version : %s " % data) # disconnect from server db.close()
def dbConnect(self): try: global db global cursor db = PyMySQL.connect("localhost", "root", "tiger", "exam") cursor = db.cursor() count = cursor.execute("select* from questions") # print(count) row = cursor.fetchall() self.table1.setRowCount(count) for i in range(0, count, 1): for j in range(0, 7, 1): self.table1.setItem(i, j, QTableWidgetItem(str(row[i][j]))) except Exception as e: print(e)
def __init__(self, user_dict): self.url = user_dict['url'] self.token1 = user_dict['token1'] self.ip = user_dict['ip'] self.user = user_dict['user'] self.password = user_dict['password'] self.database = user_dict['database'] self.localDir = user_dict['localDir'] if not os.path.exists(self.localDir): os.makedirs(self.localDir) self.db = PM.DB(ip=self.ip, user=self.user, password=self.password, database=self.database, print_sql=True)
def In(): e_code = i_code.get() e_name = i_name.get() db = database.connect('127.0.0.1', 'root', 'root', 'kytsyk_d') cursor = db.cursor() y = cursor.execute(f"SELECT Login FROM new_table WHERE Login = '******'") for row in cursor.fetchall(): y = row #print('Login: '******'******'") for row in cursor.fetchall(): t = row #print('Password: ', *row) #print(y) return [y, t]
elif finish_ts > expect_ts: late_mins = (finish_ts - expect_ts) / 60 task_info_list.append((dso_name, dso_day, expect_time, finish_day_time + ":00", late_mins, status)) return task_info_list if __name__ == '__main__': cur_day = sys.argv[1] expect_hour = str(sys.argv[2]) if (len(expect_hour) == 1): expect_hour = "0" + expect_hour oneday = datetime.timedelta(days=1) db = PyMySQL.connect("10.109.xxx", "root", "xxx", "db_calculate_overtime", charset='utf8') cursor = db.cursor() task_info_list = [] dso_tables = [{"group_name": "dict", "members": ["deskdict"]}] for dso_table in dso_tables: group_name = dso_table["group_name"] members = dso_table["members"] for dso_name in members: task_info_list = cal_summary_task(cur_day, dso_name) for task_info in task_info_list: dso_name = task_info[0] dso_day = task_info[1] expect_time = task_info[2] finish_time = task_info[3]
import ticketSentiment as s import PyMySQL db = PyMySQL.connect("localhost","maian","Gegwegpw821!!!@oj12","maian") cursor = db.cursor() cursor.execute("select comments from msp_tickets order by rand() limit 1") data = cursor.fetchone() print(data) print(s.sentiment(data))
import PyMySQL # Open database connection db = PyMySQL.connect("localhost", "testuser", "test123", "TESTDB") # prepare a cursor object using cursor() method cursor = db.cursor() # Prepare SQL query to DELETE required records sql = "DELETE FROM EMPLOYEE WHERE AGE > '%d'" % (20) try: # Execute the SQL command cursor.execute(sql) # Commit your changes in the database db.commit() except: # Rollback in case there is any error db.rollback() # disconnect from server db.close()
def __init__(self): self.conn = PyMySQL.connect('192.168.0.106', 'root', 'root', 'article_spider', charset="utf8", use_unicode=True) #虚拟机地址,用户名,密码,数据库名称,编码方式 self.cursor = self.conn.cursor()
import PyMySQL # cannot import. why?? try: db = PyMySQL.connect('localhost', 'testusr', 'test623', 'testdb') cursor = db.cursor() cursor.execute('select version()') data = cursor.fetchone() print("Database version: %s" % data) finally: db.close()
import pymysql from PyMySQL import * py = PyMySQL('localhost', 'root', 'Asd980517', 'WEININGFACE') py.create_table('FEATUREVECTOR') py.insert(['e', 'f'], [20, 20], [[1, 2, 3], [4, 5, 6]], ['2018-07-23 11:10:11', '2018-07-28 09:11:11']) py.show_all() print('==========') py.show_all() res = py.search(20, 1) print('res', res) print('=============') print('delete 7-23') py.delete(20, 1) py.show_all() res = py.search('r') print(res) print(1)
#!/usr/local/bin/python3.7 import PyMySQL db = PyMySQL.connect('192.168.1.210', 'root', 'global01a', 'print') cursor = db.cursor() query1 = 'SHOW TABLES;' res = cursor.execute(query1) for row in res: print(row) db.close()
""" Script to update the database """ import os import PyMySQL print 'Initializing database...' db = PyMySQL.connect(host="localhost", user="******", passwd="root", db="local") cur = db.cursor() cur.execute("CREATE TABLE IF NOT EXISTS tasks ( \ id INT NOT NULL AUTO_INCREMENT, \ name CHAR(100) NOT NULL, \ closed INT NOT NULL, \ PRIMARY KEY (id) \ );") cur.execute("DELETE FROM tasks;") cur.execute("INSERT INTO tasks (name, closed) VALUES ('Start learning Pyramid', 0);") cur.execute("INSERT INTO tasks (name, closed) VALUES ('Do quick tutorial', 0);") cur.execute("INSERT INTO tasks (name, closed) VALUES ('Have some beer!', 0);") db.commit() db.close()
from tkinter import * import PyMySQL as database db = database.connect('127.0.0.1', 'root', 'root', 'kytsyk_d') ''' def VVV(event): cur = db.cursor() cur.execute('SELECT * FROM new_table;') for row in cur.fetchall(): print(*row)''' def TakNi(): Vikno = Toplevel() Vikno.title("Tak Ni") Vikno.geometry("250x200") Vikno.configure(bg='#1f1f2e') Vikno.resizable(width=False, height=False) Mess = Label(Vikno, text="Логін або пароль неправильні", font=("Helvetica", 10)) Mess.place(x=34, y=16) Mess_2 = Label(Vikno, text="Можливо ви ще не зареєстровані", font=("Helvetica", 10)) Mess_2.place(x=24, y=76) Mess_3 = Label(Vikno, text="Бажаєте це зробити?", font=("Helvetica", 10)) Mess_3.place(x=58, y=98)
Created on Tue Nov 13 17:54:22 2018 @author: ambuj """ """ Python MQTT Subscription client Thomas Varnish (https://github.com/tvarnish), (https://www.instructables.com/member/Tango172) Written for my Instructable - "How to use MQTT with the Raspberry Pi and ESP8266" """ import paho.mqtt.client as mqtt import PyMySQL import datetime # Open database connection db = PyMySQL.connect("localhost","root","admin","dummy" ) # prepare a cursor object using cursor() method cursor = db.cursor() # Don't forget to change the variables for the MQTT broker! mqtt_username = "******" mqtt_password = "******" mqtt_topic = "test1" mqtt_broker_ip = "192.168.43.238" client = mqtt.Client() # Set the username and password for the MQTT client client.username_pw_set(mqtt_username, mqtt_password) # These functions handle what happens when the MQTT client connects
#!/usr/bin/python import PyMySQL # Open database connection db = PyMySQL.connect(host='127.0.0.1', user='******', password='******', database='egov') #db = MySQLdb.connect("user='******', password='******', # host='127.0.0.1', # database='egov'" ) # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("SELECT VERSION()") # Fetch a single row using fetchone() method. data = cursor.fetchone() print "Database version : %s " % data # disconnect from server db.close()
print(update_sql) def get_last_month(cur_month): cur_month_day = datetime.datetime.strptime(cur_month, '%Y-%m') last_month_first = cur_month_day.replace(day=1) last_month = last_month_first - datetime.timedelta(days=1) return last_month.strftime("%Y-%m") if __name__ == '__main__': cur_day = sys.argv[1] cur_month = cur_day[0:7] last_month = get_last_month(cur_month) db = PyMySQL.connect("10.109.13.132", "root", "iamroot", "db_calculate_overtime", charset='utf8') cursor = db.cursor() # calculate task_count and late_mins in order to insert product_task_count_dict = cal_task_count(cursor, cur_day) cal_late_mins(cursor, last_month, product_task_count_dict) db.commit() time.sleep(1) # calculate chain_ratio in order to update cal_chain_ratio(cursor, last_month, 'work') cal_chain_ratio(cursor, last_month, 'natural') db.commit() db.close()
import PyMySQL # Open database connection db = PyMySQL.connect("localhost","root","","TESTDB" ) # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("SELECT VERSION()") # Fetch a single row using fetchone() method. data = cursor.fetchone() print ("Database version : %s " % data) # disconnect from server db.close()
import PyMySQL # Open database connection db = PyMySQL.connect("krzychu.mysql.pythonanywhere-services.com","krzychu","krzychu$default","CAMtASIA" ) # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("SELECT VERSION()") # Fetch a single row using fetchone() method. data = cursor.fetchone() print ("Database version : %s " % data) # disconnect from server db.close()
import PyMySQL # Open database connection db = PyMySQL.connect("krzychu.mysql.pythonanywhere-services.com", "krzychu", "krzychu$default", "CAMtASIA") # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("SELECT VERSION()") # Fetch a single row using fetchone() method. data = cursor.fetchone() print("Database version : %s " % data) # disconnect from server db.close()
def connectDB(self): global db global cursor db = PyMySQL.connect("localhost", "root", "tiger", "exam") cursor = db.cursor()
import PyMySQL # Open database connection print('logging into database') try: db = PyMySQL.connect("localhost", "root", "raspberry", "weather") except Exception: print('error connecting to database') # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("SELECT VERSION()") # Fetch a single row using fetchone() method. data = cursor.fetchone() print("Database version : %s " % data) # disconnect from server db.close()
import PyMySQL PyMySQL.install_as_MySQLdb()
def __init__(self): self.DbConnection = PyMySQL.connect(host='localhost', user='******', password='******', db='vbothome', charset='utf8mb4', cursorclass=PyMySQL.cursors.DictCursor)