Browse Source

更改general_clickbot

zooeytsai 2 năm trước cách đây
mục cha
commit
d57c7974ba

+ 0 - 2
INNNews/general_clickbot.py

@@ -14,8 +14,6 @@ import random
 import requests
 import datetime
 import dataset
-import pymysql
-pymysql.install_as_MySQLdb()
 import time
 import traceback
 import sys

+ 4 - 4
INNNews/get_spread.py

@@ -20,7 +20,7 @@ def save_sheet(df,filename,tabname,startpos='A1'):
     scope = ['https://spreadsheets.google.com/feeds',
             'https://www.googleapis.com/auth/drive']
 
-    credentials = ServiceAccountCredentials.from_json_keyfile_name('c:\\keys\\innnews-d27b01472ba2.json', scope)
+    credentials = ServiceAccountCredentials.from_json_keyfile_name('/Users/zooeytsai/kw_tools/INNNews/innnews-d27b01472ba2.json', scope)
     gc = gspread.authorize(credentials)
     spread = Spread(filename,creds=credentials)
 
@@ -31,13 +31,13 @@ def get_sheets(filename):
     scope = ['https://spreadsheets.google.com/feeds',
             'https://www.googleapis.com/auth/drive']
 
-    credentials = ServiceAccountCredentials.from_json_keyfile_name('c:\\keys\\innnews-d27b01472ba2.json', scope)
+    credentials = ServiceAccountCredentials.from_json_keyfile_name('/Users/zooeytsai/kw_tools/INNNews/innnews-d27b01472ba2.json', scope)
     gc = gspread.authorize(credentials)
 #    files=gc.list_spreadsheet_files()
 #    print(files)
     spread = Spread(filename,creds=credentials)
 
-    df=spread.sheet_to_df(sheet='2022')
+    df=spread.sheet_to_df(sheet='2022')
     for idx,row in df.iterrows():
         r1=row[1].strip()
         if len(r1)>1:
@@ -46,7 +46,7 @@ def get_sheets(filename):
             result.append({'kw':r1+" "+r2+" "+r3})
     return result
 
-result=get_sheets('引新聞xSEO團隊共用表單')
+result=get_sheets('引新聞INNEWS稿單xSEO優化')
 js=json.dumps(result, ensure_ascii=False)
 
 print(js)

+ 14 - 12
INNNews/notifytest.py

@@ -32,17 +32,19 @@ def send_msg(kw):
     params = {"message": kw}  
     r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
 
-db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
-cursor=db.query('SELECT * FROM seo.general_log where domain = "innews.com.tw" and datediff(now(),dt)=0 order by dt desc')
-result="\n"
-idx=0
-for c in cursor:
-    idx+=1
-    if idx<=3:
-        elmt=c['kw']
-        result+="["+str(c['ranking'])+"]:"+elmt+"\n"
-
-msg="\n機器人執行次數:"+str(idx)
-send_msg(msg+result)
+while True:
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+    cursor=db.query('SELECT * FROM seo.general_log where domain = "innews.com.tw" and datediff(now(),dt)=0 order by dt desc')
+    result="\n"
+    idx=0
+    for c in cursor:
+        idx+=1
+        if idx<=3:
+            elmt=c['kw']
+            result+="["+str(c['ranking'])+"]:"+elmt+"\n"
+    
+    msg="\n機器人執行次數:"+str(idx)
+    send_msg(msg+result)
+    time.sleep(1800)
 
 # schtasks /create /sc minute /mo 10 /st 09:00 /et 23:00 /tn "linebat" /tr "C:\tmp\inn_line.bat"

+ 19 - 7
INNNews/run_sheet.py

@@ -13,14 +13,26 @@ from gspread_pandas import Spread, Client
 from oauth2client.service_account import ServiceAccountCredentials
 import os
 import redis
+import time
+
 r = redis.Redis(host='db.ptt.cx', port=6379, db=1,password='choozmo9')
 js=r.get('innews_sheet')
 jsobj=json.loads(js)
-kw=random.choice(jsobj)
-print(kw['kw'])
-if os.name == 'nt':
-    py='python'
-else:
-    py='python3'
+while True:
+    kw=random.choice(jsobj)  # 第一次(三組關鍵字)
+    
+    kw_innews = '引新聞 ' # 第二次(隨機選擇兩組關鍵字與引新聞)
+    num = random.choices([0,1,2],k=2)
+    for i in num:
+        kw_innews+=kw['kw'].split(' ')[i]+' '
+    print(kw)
+    
+    
+    os.chdir('/Users/zooeytsai/kw_tools/INNNews')
+    os.system('python3 general_clickbot_local.py get --kw="'+kw['kw']+'" --domain=innews.com.tw')
+    print('等待')
+    time.sleep(120)
+# time.sleep(120)
+# os.system('python3 general_clickbot.py get --kw="'+kw_innews+'" --domain=innews.com.tw')
 
-os.system(py+' general_clickbot.py get --kw="'+kw['kw']+'" --domain=innews.com.tw')
+# os.system('python notifytest.py send_msg')

+ 8 - 7
SEO/clickbot_100.py

@@ -9,6 +9,7 @@ import time
 import urllib
 import argparse
 import schedule
+
 import logging
 import sys
 from logging.handlers import SysLogHandler
@@ -36,10 +37,10 @@ def restart_browser():
 
 
 def process_one():
-    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+    db = dataset.connect('mysql://root:jondae350@localhost:3306/ig_tags?charset=utf8mb4')
     lst=[]
-    table=db['save_result']
-    cursor=db.query('select term from selected_kw where client="清原" and term not in (SELECT distinct(keyword) FROM seo.save_result where url like "%taroboba-yuan.com%" and datediff(now(),dt)=0)')
+    table=db['google_rank']
+    cursor=db.query('select term from selected_kw and term not in (SELECT distinct(keyword) FROM ig_tags.save_result where url like "%beastparadise.net%" and datediff(now(),dt)=0)')
     for c in cursor:
         lst.append(c['term'])
 
@@ -54,7 +55,7 @@ def process_one():
     driver.get(googleurl)
     time.sleep(6)
     fname=term.replace(' ','_')
-    driver.save_screenshot('c:/tmp/seo/'+fname+'.png')
+    # driver.save_screenshot('c:/tmp/seo/'+fname+'.png')
     df=pd.DataFrame()
 
     elmts=driver.find_elements_by_xpath("//div[@class='yuRUbf']/a")
@@ -94,7 +95,7 @@ def process_one():
     df['結果網址']=datadict['結果網址']
     df['結果名次']=datadict['結果名次']
 
-    df.to_excel('c:/tmp/seo/'+fname+".xls")
+    df.to_excel('/Users/zooeytsai/'+fname+".xls")
 
     driver.quit()
 
@@ -106,8 +107,8 @@ args = parser.parse_args()
 
 if args.loop:
 
-    schedule.every(6).minutes.do(process_one)
-#    schedule.every(0.4).minutes.do(process_one)
+#    schedule.every(6).minutes.do(process_one)
+    schedule.every(0.4).minutes.do(process_one)
 
     while True:
         schedule.run_pending()

+ 20 - 13
choozmo/googlenews.py

@@ -4,21 +4,26 @@ from GoogleNews import GoogleNews
 
 def news(title_and_link):
     for i in title_and_link:
-        article = Article(i['link'])
-        article.download()
-        article.parse()
-        text = article.text
-        title = i['title']
         try:
-            with open(f'/googlenews/{title}.txt', 'x') as f:
-                f.write(text)
-        except FileExistsError:
-            print('已有同樣新聞文章')
+            article = Article(i['link'])
+            article.download()
+            article.parse()
+            text = article.text
+            title = i['title']
+            try:
+                print(title)
+                with open(f'/Users/zooeytsai/ig_tags/googlenews/{title}.txt','x') as f:
+                    f.write(text)
+            except FileExistsError:
+                print('已有同樣新聞文章','title')
+                pass
+        except:
+            print('403')
             pass
     return text
 
 
-def google_news(keyword, page):
+def google_news(keyword,page):
     g = GoogleNews()
     g.setlang('cn')
     g.setencode('utf-8')
@@ -29,7 +34,7 @@ def google_news(keyword, page):
         g.get_page(page)
         result = g.result()
         for j in result:
-            d = {'title': j['title'], 'link': j['link']}
+            d ={'title':j['title'],'link':j['link']}
             news_link.append(d)
     g.clear()
     print(len(news_link))
@@ -37,5 +42,7 @@ def google_news(keyword, page):
     return news_link
 
 
-result = google_news('地震', 1)
-news(result)
+k = ['寵物蛋糕','寵物住宿','寵物餐廳','寵物用品','寵物美容','寵物友善']
+for i in k:
+    result = google_news(i,5)
+    news(result)

+ 5 - 4
choozmo/gsearch_general.py

@@ -13,14 +13,14 @@ import random
 from bs4 import BeautifulSoup
 import requests
 import time
-import rpyc
+# import rpyc
 import sys
 import docker
-import  googlesearch
+# import googlesearch
 import codecs
 import sys
 import time
-import dataset
+# import dataset
 import os
 
 def process_one(driver):
@@ -50,6 +50,7 @@ def process_query(driver,qs,number_results=10,language_code='en',enable_next=Tru
         totallst+=lst
         try:
             if enable_next:
+                time.sleep(3)
                 elmt=driver.find_element_by_xpath("//a[@id='pnnext']")
                 webdriver.ActionChains(driver).move_to_element(elmt).perform()
                 webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
@@ -72,7 +73,7 @@ def restart_browser():
 
     options = webdriver.ChromeOptions()
 #    options.add_argument("--proxy-server=http://80.48.119.28:8080")
-    driver=webdriver.Chrome(options=options)
+    driver=webdriver.Chrome(executable_path='/Users/zooeytsai/Downloads/chromedriver',options=options)
 
 #    driver=webdriver.Chrome(desired_capabilities=options.to_capabilities())
     #driver = webdriver.Remote(

+ 13 - 8
choozmo/term_get_email.py

@@ -13,15 +13,17 @@ import random
 from bs4 import BeautifulSoup
 import requests
 import time
-import rpyc
+# import rpyc
 import sys
 import docker
-import  googlesearch
+# import googlesearch
 import codecs
 import sys
 import time
 import dataset
 import os
+import pymysql
+pymysql.install_as_MySQLdb()
 
 def process_one(driver):
     lst=[]
@@ -49,7 +51,6 @@ def process_query(driver,url):
         txt=txt.replace('mailto:','')
         if 'mailto:?subject=' in txt:
             return None
-
         return txt
     except:
         print('not found')
@@ -67,18 +68,20 @@ def process_query(driver,url):
 
 result=[]
 driver=None
+path = '/Users/zooeytsai/Downloads/chromedriver'
 
 def restart_browser():
 #    os.system('docker container restart p4444')
 #    time.sleep(10)
 
     options = webdriver.ChromeOptions()
+    options.add_argument("--headless")
     options.add_argument("start-maximized")
-    options.add_argument('user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data')
+    options.add_argument('user-data-dir=/Users/zooeytsai/Library/Application Support/Google/Chrome/Default')
 #    options.add_argument('--profile-directory=Profile 77')
     options.add_argument('--profile-directory=Default')
 
-    driver=webdriver.Chrome(chrome_options=options)
+    driver=webdriver.Chrome(options=options,executable_path=path)
     #driver = webdriver.Remote(
     #    command_executor='http://127.0.0.1:4444/wd/hub',
     #desired_capabilities=options.to_capabilities())
@@ -87,15 +90,17 @@ def restart_browser():
     return driver
 
 db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
-cursor=db.query('select title,url,tag from term_gsearch where url not in (select url from term_progress) order by rand()')
+# cursor=db.query('select title,url,tag from term_gsearch where url not in (select url from term_progress) and tag like "區塊鏈" order by rand()')
+cursor=db.query('select title,url,tag from term_gsearch where tag like "區塊鏈" order by rand()')
 lst=[]
 for c in cursor:
     lst.append(c)
-    
+
 table=db['term_progress']
 driver=restart_browser()
 for c in lst:
     email=process_query(driver,c['url'])
+    print(email)
     c['title']=c['title'].replace('聯絡我們 - ','')
     c['title']=c['title'].replace('聯絡我們-','')
     c['title']=c['title'].replace('聯絡我們|','')
@@ -106,4 +111,4 @@ for c in lst:
     c['title']=c['title'].replace('聯絡我們','')
 
     table.insert({'title':c['title'],'url':c['url'],'email':email,'tag':c['tag']})
-#    time.sleep(3)
+    time.sleep(2)

+ 2 - 2
choozmo/term_gsearch.py

@@ -126,7 +126,7 @@ driver=gsearch_general.restart_browser()
 #idx=gsearch_general.process_query(driver,'聯絡我們 mail 改運',number_results=100,language_code='zh-TW')
 # idx=gsearch_general.process_query(driver,'聯絡我們 mail 風水',number_results=100,language_code='zh-TW')
 # idx=gsearch_general.process_query(driver,'聯絡我們 mail 公益',number_results=100,language_code='zh-TW')
-idx=gsearch_general.process_query(driver,'聯絡我們 mail 區塊鏈',number_results=100,language_code='zh-TW')
+idx=gsearch_general.process_query(driver,'聯絡我們 區塊鏈',number_results=100,language_code='zh-TW')
 
 
 
@@ -135,7 +135,7 @@ idx=gsearch_general.process_query(driver,'聯絡我們 mail 區塊鏈',number_re
 # print(idx)
 for x in idx:
     x['dt']=datetime.datetime.now()
-    x['tag']='區塊鏈'
+    x['tag']='區塊鏈2'
     print(x)
     table.insert(x)
 

+ 61 - 15
openshot/examples/beginner.py

@@ -1,5 +1,33 @@
 import openshot
 
+
+def cKey(r,g,b,fuzz):
+    col=openshot.Color()
+    col.red=openshot.Keyframe(r)
+    col.green=openshot.Keyframe(g)
+    col.blue=openshot.Keyframe(b)
+    return openshot.ChromaKey(col, openshot.Keyframe(fuzz))
+
+
+def video_photo_clip(video=None, layer=None, position=None, end=None
+                     , scale_x=1, scale_y=1, location_x=0, location_y=0, ck=None, audio=True):
+    clip = openshot.Clip(video)
+    clip.Layer(layer)
+    clip.Position(position)
+    clip.End(end)
+    clip.scale_x = openshot.Keyframe(scale_x)
+    clip.scale_y = openshot.Keyframe(scale_y)
+    clip.location_x = openshot.Keyframe(location_x)
+    clip.location_y = openshot.Keyframe(location_y)
+    
+    if ck != None:
+        clip.AddEffect(ck)
+    if audio == True:
+        clip.has_audio = openshot.Keyframe(1)
+    else:
+        clip.has_audio = openshot.Keyframe(0)
+    return clip
+
 def video_writer_init(path):
     w = openshot.FFmpegWriter(path)
     w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
@@ -8,21 +36,39 @@ def video_writer_init(path):
     return w
 
 
-t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
-t.Open()
-text_title = openshot.QtImageReader("/app/tt.jpg")
-clip = openshot.Clip(text_title)
-t.AddClip(clip)
-
-w = video_writer_init("/app/test.mp4")
-w.Open()
-
-frames = t.info.fps.ToInt ()*3
-for n in range(frames):
-    f=t.GetFrame(n)
-    w.WriteFrame(f)
+def create_video(bg, title_bg,time):
+    t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
+    t.Open()
+    
+    ck = cKey(0, 254, 0, 270)
+    ck_anchor = cKey(0, 255, 0, 320)
+    
+    anchor_video = openshot.FFmpegReader(bg)  # 影片
+    anchor_video.Open()
+    anchor_clip_video = video_photo_clip(video=anchor_video, layer=2, scale_x=0.59, scale_y=0.59, location_x=-0.04, location_y=-0.04, position=0, end=70, ck=None, audio=True)
+    t.AddClip(anchor_clip_video)
+    anchor_video.Close()
+    
+    anchor_template = openshot.FFmpegReader(title_bg)  # 樣板
+    anchor_template.Open()
+    anchor_clip_template = video_photo_clip(video=anchor_template, layer=1, scale_x=1, scale_y=1,
+                                    location_x=0, location_y=0, position=0, end=70, ck=None, audio=True)
+    t.AddClip(anchor_clip_template)
+    anchor_template.Close()
+    
+    w = video_writer_init("/app/output/A-2-1.mp4")
+    w.Open()
+    # frames = int(t.info.fps)*int(time)
+    frames = t.info.fps.ToInt()*int(time)
+    print('結果一',frames)
+    for n in range(frames):
+        # tmp = n%(int(t.info.fps)*3) +int(t.info.fps)*int(2)
+        f=t.GetFrame(n)
+        w.WriteFrame(f)
 
-t.Close()
-w.Close()
+    t.Close()
+    w.Close()
 
 
+if __name__ == '__main__':
+    create_video("/app/input/movie_main/C0048.mp4","/app/input/bg/串場樣板1.mp4",61)

+ 11 - 11
openshot/openshotExample.py → openshot/examples/openshotExample.py

@@ -1,3 +1,4 @@
+# coding:utf-8
 import openshot
 import re
 from PIL import Image,ImageDraw,ImageFont
@@ -59,21 +60,19 @@ def text_to_short_vedio(bg,title_bg,text,title,time):
     t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
     t.Open()
     
-    # 去背參數
     ck=cKey(0,254,0,270)
     ck_anchor=cKey(0,255,0,320)
 
-    anchor = openshot.QtImageReader(bg)
+    anchor = openshot.FFmpegReader(bg) # 影片
     anchor.Open()
-    anchor_clip = video_photo_clip(video=anchor,layer=2,scale_x=1,scale_y=1,
-            location_x=0,location_y=0,position=0, end=5,ck=ck_anchor,audio=True)
+    anchor_clip = video_photo_clip(video=anchor, layer=2, scale_x=0.59, scale_y=0.59,location_x=-0.04, location_y=-0.04, position=0, end=5, ck=ck_anchor, audio=True)
     t.AddClip(anchor_clip)
     anchor.Close()
 
-    anchor3 = openshot.FFmpegReader(title_bg)
+    anchor3 = openshot.FFmpegReader(title_bg) # 樣板
     anchor3.Open()
-    anchor_clip3 = video_photo_clip(video=anchor3,layer=3,scale_x=0.34,scale_y=0.34,
-            location_x=0.33,location_y=-0.34,position=0, end=5,ck=ck_anchor,audio=True)
+    anchor_clip3 = video_photo_clip(video=anchor3, layer=1, scale_x=1, scale_y=1,
+                                   location_x=0, location_y=0, position=0, end=5, ck=ck_anchor, audio=True)
     t.AddClip(anchor_clip3)
     anchor3.Close()
 
@@ -94,10 +93,11 @@ def text_to_short_vedio(bg,title_bg,text,title,time):
     text_title.Close()
 
 
-    w = video_writer_init("output/test2.mp4")
+    w = video_writer_init("/app/output/test_op.mp4")
     w.Open()
-
-    frames = int(t.info.fps)*int(time)
+    # frames = int(t.info.fps)*int(time)
+    frames = t.info.fps.ToInt()*int(time)
+    print('結果一',frames)
     for n in range(frames):
         # tmp = n%(int(t.info.fps)*3) +int(t.info.fps)*int(2)
         f=t.GetFrame(n)
@@ -108,4 +108,4 @@ def text_to_short_vedio(bg,title_bg,text,title,time):
 
 
 if __name__ == '__main__':
-    text_to_short_vedio("input/bg/客家_BG.png","input/title/右上角桐花.MOV","測試content","標題測試",3)
+    text_to_short_vedio("/app/input/movie_main/C0050.mp4","/app/examples/主播示意1.mp4","測試content","標題測試",14)

BIN
openshot/output/test.mp4


BIN
openshot/output/test2.mp4