Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Feb 6, 2024
1 parent 55bd5b7 commit 9d51564
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,36 @@ def setup_driver(self):
return driver

def getChannelItems(self):
# 打开source文件并读取所有行
# open the source file and read all lines
with open(self.source_file, 'r', encoding='utf-16') as f:
lines = f.readlines()

# 创建一个空字典来存储频道和其对应的URL
# create a dictionary to store the channels
channels = {}
current_channel = ''
pattern = r"^(.*?),(?!#genre#)"

# 遍历每一行
for line in lines:
line = line.strip()
if '#genre#' in line:
# 这是一个新的频道分类名称
# This is a new channel, create a new key in the dictionary
current_channel = line.split(',')[0]
channels[current_channel] = []
else:
# 这是一个频道名称,添加到当前频道分类列表中
# This is a url, add it to the list of urls for the current channel
match = re.search(pattern, line)
if match and match.group(1) not in channels[current_channel]:
channels[current_channel].append(match.group(1))

return channels

def outputTxt(self,cate,channelUrls):
# 创建一个新的final文件
with open(self.finalFile, 'a', encoding='utf-16') as f:
for name, urls in channelUrls.items():
f.write(cate + ',#genre#\n')
for url in urls:
f.write(name + ',' + url + '\n')

def getSpeed(self,url):
start = time.time()
try:
r = requests.get(url,timeout=4)
resStatus = r.status_code
except:
print('请求超时或失败')
print('request timeout or error')
end = time.time()
return end - start

Expand All @@ -94,6 +85,14 @@ def removeFile(self):
if os.path.exists(self.finalFile):
os.remove(self.finalFile)

def outputTxt(self,cate,channelUrls):
# update the final file
with open(self.finalFile, 'a', encoding='utf-16') as f:
f.write(cate + ',#genre#\n')
for name, urls in channelUrls.items():
for url in urls:
f.write(name + ',' + url + '\n')

def visitPage(self,channelItems):
self.driver.get("https://www.foodieguide.com/iptvsearch/")
self.removeFile()
Expand Down

0 comments on commit 9d51564

Please sign in to comment.