Last active
February 9, 2019 10:54
-
-
Save sleepless-se/ecc479fffa940e3a7f871f3c57be6cfb to your computer and use it in GitHub Desktop.
asos
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 os,pymysql.cursors | |
def get_error_ids(): | |
ids=[] | |
img_paths = os.listdir('./') | |
for img_path in img_paths: | |
if 'sale-error' not in img_path: continue | |
_id = img_path.split('-')[0] | |
ids.append(_id) | |
return ids | |
def delete_id_from_download(ids): | |
connection = pymysql.connect( | |
host="", | |
user="", | |
passwd="", | |
db='', | |
charset='utf8mb4', | |
cursorclass=pymysql.cursors.DictCursor | |
) | |
try: | |
with connection.cursor() as cursor: | |
for _id in ids: | |
sql = "delete from `Download` where `downloadId` = %s" | |
cursor.execute(sql, (_id)) | |
connection.commit() | |
print(f'delete {_id}') | |
finally: | |
connection.close() | |
def delete_img(ids): | |
for _id in ids: | |
img_paths = os.listdir('./') | |
for img_path in img_paths: | |
if _id in img_path: | |
os.remove(img_path) | |
print(f'delete {img_path}') | |
if __name__ == "__main__": | |
ids = get_error_ids() | |
delete_id_from_download(ids) | |
delete_img(ids) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0 0 * * * cd ~/Desktop/BUYMA/error/img && python3 ./delete_error_id_from_download.py