Author: admin
Date: 23-01-2024, 22:59
from ast import If, IfExp
import webbrowser
import pandas as pd
from time import sleep
# https://docs.google.com/spreadsheets/d/1wiDhK4DnADdto6W2zY9nvYkUxsoSM8HjpMSGWV67V_Y/edit#gid=0
#get spreadsheets key from url
gsheetkey = "1wiDhK4DnADdto6W2zY9nvYkUxsoSM8HjpMSGWV67V_Y"
#sheet name
sheet_name = 'LINK'
# STT Link Profile
# 1 https://thiencntt.com Profile 1
# 2 https://vnexpress.net Profile 1
# 3 https://tuoitre.vn Profile 2
url=f'https://docs.google.com/spreadsheet/ccc?key={gsheetkey}&output=xlsx'
exDataDf = pd.read_excel(url,sheet_name=sheet_name)
numLink = exDataDf.shape[0]
numNewLink = numLink
# print(numLink)
# Windows
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'
# Mở link ở cmd để coi danh sách profile
# "C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data"
for i in range(0, numLink):
sleep(2)
print(exDataDf.iloc[i]["Link"])
if type(exDataDf.iloc[i]["Profile"]) == str:
profile = exDataDf.iloc[i]["Profile"]
else:
profile = "Default"
webbrowser.get(chrome_path + ' --profile-directory="{}" %s'.format(profile)).open(exDataDf.iloc[i]["Link"])
# khi mở code thì chạy các lệnh trên lần đầu để có số lượng link, mở các link đã có
# Vào vòng lặp while để check có link mới không
print("Vao vong lap While")
while numNewLink <= numLink: # Nếu số lượng link mới <= số lượng link cũ thì vào vòng lặp để check
print("Wait 10 second")
sleep(10) # Ngưng 10 giây và check lại
exDataDfNew = pd.read_excel(url,sheet_name=sheet_name)
print(exDataDfNew.shape[0])
numNewLink = exDataDfNew.shape[0]
# Tiến hành mở các link mới
if numNewLink > numLink:
for j in range(numLink, numNewLink):
sleep(2)
if type(exDataDfNew.iloc[j]["Profile"]) == str:
profile = exDataDfNew.iloc[j]["Profile"]
else:
profile = "Default"
print(profile)
webbrowser.get(chrome_path + ' --profile-directory="{}" %s'.format(profile)).open(exDataDfNew.iloc[i]["Link"])
numLink = numNewLink # Nếu số lượng link mới lớn hơn thì gán số lượng link cũ = link mới