|
@@ -0,0 +1,75 @@
|
|
|
+from model.sql_models import DB
|
|
|
+from config.using_config import quchen_text, dm
|
|
|
+import pandas
|
|
|
+import requests
|
|
|
+import time
|
|
|
+
|
|
|
+def update_media_info():
|
|
|
+
|
|
|
+ sql = '''
|
|
|
+ select foo.account_id ,access_token ,image_ids from
|
|
|
+ (select account_id ,group_concat(image_id) as image_ids from adcreative_info ai
|
|
|
+ where is_video =0 and length (account_id )>1
|
|
|
+ group by account_id ) as foo
|
|
|
+ left join
|
|
|
+ (select account_id,access_token,'MP' as type from advertiser_vx av
|
|
|
+ union
|
|
|
+ select account_id ,access_token,'GDT' as type from advertiser_qq aq ) as foo2
|
|
|
+ on foo.account_id=foo2.account_id
|
|
|
+ order by foo.account_id
|
|
|
+ limit 10
|
|
|
+ '''
|
|
|
+ df = pandas.read_sql(sql=sql, con=db_qc.engine)
|
|
|
+ print(df)
|
|
|
+ for row in df.rows():
|
|
|
+
|
|
|
+
|
|
|
+ print(row)
|
|
|
+ user_sql = '''
|
|
|
+ select * from
|
|
|
+ where
|
|
|
+ '''
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+from PIL import Image
|
|
|
+from io import BytesIO
|
|
|
+
|
|
|
+
|
|
|
+def update_image_info():
|
|
|
+ while True:
|
|
|
+ user_sql='''
|
|
|
+ select * from image_info ii
|
|
|
+ where preview_url is not null
|
|
|
+ and size is null
|
|
|
+ limit 100
|
|
|
+ '''
|
|
|
+ df=pandas.read_sql(user_sql,con=db_qc.engine)
|
|
|
+ if len(df)==0:
|
|
|
+ break
|
|
|
+ for index,row in df.iterrows():
|
|
|
+ try:
|
|
|
+ print(row['preview_url'])
|
|
|
+ rsp=requests.get(row['preview_url'])
|
|
|
+
|
|
|
+ im = Image.open(BytesIO(rsp.content))
|
|
|
+
|
|
|
+ image_format = im.format
|
|
|
+ image_size = len(rsp.content)
|
|
|
+
|
|
|
+ sql=''' update image_info set size={},type='{}'
|
|
|
+ where image_id = '{}' '''.format(image_size,image_format,row['image_id'])
|
|
|
+ db_qc.session.execute(sql)
|
|
|
+ db_qc.session.commit()
|
|
|
+ except Exception as e:
|
|
|
+ time.sleep(1)
|
|
|
+ print(e)
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ db_qc = DB(config=quchen_text)
|
|
|
+ db_dm = DB(config=dm)
|
|
|
+
|
|
|
+ update_image_info()
|