Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
Last active February 9, 2019 10:54
Show Gist options
  • Save sleepless-se/ecc479fffa940e3a7f871f3c57be6cfb to your computer and use it in GitHub Desktop.
Save sleepless-se/ecc479fffa940e3a7f871f3c57be6cfb to your computer and use it in GitHub Desktop.
asos
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)
@sleepless-se
Copy link
Author

0 0 * * * cd ~/Desktop/BUYMA/error/img && python3 ./delete_error_id_from_download.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment