Created
June 10, 2021 21:14
-
-
Save ufo22940268/f08c09b6c37698d9f53a135b88d05107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymysql | |
from openpyxl import load_workbook | |
def write_to_db(conn, id, src_type, run_args): | |
src_type = 1 if src_type == '云更新' else 0 | |
cursor = conn.cursor() | |
sql = "update game_infos set src_type = %s, run_args = %s where id = %s;" | |
cursor.execute(sql, (src_type, run_args, id)) | |
if __name__ == '__main__': | |
conn = pymysql.connect( | |
host='localhost', | |
user='root', | |
port=55003, | |
password='my-secret-pw', | |
database='public', | |
charset='utf8' | |
) | |
wb = load_workbook(filename='小悟云游戏对应ID.xlsx') | |
ws = wb.active | |
for i, row in enumerate(ws): | |
if i == 0: | |
continue | |
line = [str(cell.value) for cell in row if cell.value is not None] | |
if line: | |
write_to_db(conn, line[3], line[2], line[1]) | |
conn.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment