def file2db(file, zhinengleibie, province): conn = get_conn() filename = path.split(file)[-1] job_id = filename.replace(".html", "") exists = conn.execute( f"select count(1) from jobs where job_id='{job_id}' and year_month={year_month}" ).fetchall()[0][0] if exists: try_rename(file) return #print(file) job = file2job(file, zhinengleibie, province) if not job: try_rename(file) return data = pd.DataFrame(columns=get_featurenames(job)) l = object2list(job) data.loc[job.job_id] = l data.to_sql("jobs", conn, if_exists="append", index=False) conn.close() try_rename(file)
def file2db(file, city): conn = get_conn() try: filename = path.split(file)[-1] job_id = filename.replace(".html", "") exists = conn.execute( "select count(1) from _51jobs where job_id='{0}'".format( job_id)).fetchall()[0][0] if exists: os.rename(file, file.replace("51jobs", "51jobs_back")) return print(file) job = file2job(file, city) if not job: return # if not job.check_all(): # return data = pd.DataFrame(columns=get_featurenames(job)) l = object2list(job) data.loc[job.job_id] = l data.to_sql("_51jobs", conn, if_exists="append", index=False) except Exception: pass finally: conn.close()