garfield.py 733 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python
  2. import requests
  3. import random
  4. from calendar import monthrange
  5. COMIC = "garfield"
  6. #def random_date():
  7. # year_list = list(range(1979, 2021))
  8. # year = year_list[random.randint(0,len(year_list))]
  9. # month = str(random.randint(1,12)).zfill(2)
  10. # days = monthrange(int(year),int(month.replace("0","")))[1]
  11. # day = str(random.randint(1,days)).zfill(2)
  12. # return f"{year}/{month}/{day}"
  13. def image_url(url):
  14. data = requests.get(url, allow_redirects=True).text
  15. loc = data.find('https://assets.amuniversal.com/')
  16. image = data[loc:loc+63]
  17. return image
  18. print(image_url)
  19. def main():
  20. print(image_url("https://www.gocomics.com/random/"+COMIC))
  21. if __name__ == "__main__":
  22. main()