如何避免Heroku dyno睡眠为我的网页剪贴板[重复]

2hh7jdfx  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(89)

此问题在此处已有答案

Is there a way to prevent web dynos from going to sleep?(1个答案)
How to keep App awake on Heroku using free dyno(1个答案)
Best way to keep Heroku awake with 1 dyno(1个答案)
21天前关闭
我已经写了这个python web scraper脚本,并将其部署在Heroku上。它是持续运行的脚本,并在睡眠后的每一分钟进行web scraping。问题是,它可以正常工作几分钟,然后停止做任何事情。我认为dyno去睡眠。我怎么能防止这种情况?我怎么能让我的脚本运行而没有dyno闲置或其他一些问题在这里发生?

import time
from bs4 import BeautifulSoup
import urllib.request
import schedule
from bs4.element import Tag

url = 'url_here'  
prev_news = []  # Store the previous state of news to compare changes
prev_updated = "Initial Value"
updated_news = []

   
def compare_variables(prev, curr):
   """
   Compare two variables and print the comparison result.
   """
   if prev == curr:
       print("No change values")
       return False
   else:
       print("Change detected")
       return True
   
def fetch_last_updated() -> str:
   page = urllib.request.urlopen(url)
   soup = BeautifulSoup(page.read(), 'html.parser')
  """
  .......
  """
   return last_updated

def fetch_latest_news() -> list:
   """
   ...
   """
   return latest_news


def value(component: Tag) -> list:
   result = []
   """
   ...
   """
   return result

def change_link(url: str) -> str:
   if url != None:
       """
       ...
       """
       return url
   else:
       return None
   

def job():
     # Fetch last updated information from DTU Official Webpage
       curr_updated = fetch_last_updated()
       print("Runnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnning")
       # Compare the two variables
       if compare_variables(prev_updated, curr_updated):
           # Changes detected in last updated information
           print("Last Updated has changed to :", curr_updated)

           curr_news = fetch_latest_news()

       # Update the previous value for the next iteration
       prev_updated = curr_updated

schedule.every(1).minutes.do(job)

if __name__ == "__main__":
  
  while True:
   schedule.run_pending()
   time.sleep(1)

字符串

gc0ot86w

gc0ot86w1#

也许你可以尝试定期使用外部应用程序(例如Kaffeine)ping你的应用程序。

相关问题