idk the script instantly closes and does nothing. check it please import requests import…
- User
idk the script instantly closes and does nothing. check it please import requests import time import json
WEBHOOK_URL = “https://discord.com/api/webhooks/1130786757609267241/I1Dv_QmHX_EwEVUHagrCWqfVmbXk3eqIGrDRhqCIBwaEjql-soQw88IJRMRUz1_amcZD” CHECK_INTERVAL = 1 # Check for new chapters every hour
def send_notification(chapter_number, chapter_title, manga_cover): data = { “content”: f"Вышла новая Глава {chapter_number} - {chapter_title}!!“, “embeds”: [ { “image”: { “url”: manga_cover } } ] } headers = { “Content-Type”: “application/json” } response = requests.post(WEBHOOK_URL, data=json.dumps(data), headers=headers) if response.status_code != 204: print(“Failed to send notification.”)
def check_for_new_chapter(): url = “https://mangalib.me/yu-yu-hakusho-digital-colored?section=chapters&ui=6398976” response = requests.get(url) if response.status_code == 200:
Example: Parsing the webpage to find the latest chapter title, number, and manga cover
html = response.text start_index = html.index(‘Chapters’) end_index = html.index(‘Comments’) chapter_list_html = html[start_index:end_index] chapters = chapter_list_html.split(‘<a class="tile__name’)
latest_chapter_title = chapters[1].split(”>“)[1].split(”</a")[0].strip() latest_chapter_number = int(latest_chapter_title.split(“Том”)[1].split(“Глава”)[1].split(“-”)[0].strip())
manga_cover = html.split(‘<img src="’)[1].split(‘" alt="’)[0]
Check if the latest chapter is different from the last known one (you can store it in a file or database)
If it’s different, send a notification
with open(“last_known_chapter.txt”, “r”) as file: last input(‘Press ENTER to exit’)
- Assistant
The script provided seems to have a few issues:
-
The webhook URL provided is invalid or incomplete. Make sure you have a valid Discord webhook URL and replace it in the
WEBHOOK_URLvariable. -
The function
send_notification()is not properly indented. Indent the function body after the function definition. -
The
lastvariable is incomplete in the last line. It seems there is missing code or a mistake in that line. Verify and update it accordingly.
To further investigate any other potential issues, please provide the missing code or correct the existing code in the last line of the script.
-
- User
you said this but didnt finish sentence I’ve noticed that there is a missing line of code in your script, which is likely causing the issue. After the line with open("last_known_chapter.txt", "r") as file:, there should be a line to read the last known chapter number from the file and store it in a variable.
Here’s the updated code with the missing line added:
with open(“last_known_chapter.txt”, “r”) as file: last_known_chapter = int(file.read().strip())
Additionally, you may want to add a line to update the last_known_chapter.txt file with the latest chapter number after sending the notification. You can do this right after the line send_notification(latest_chapter_number, latest_chapter_title, manga_cover):
with open(“last_known_chapter.txt”, “w”) as file: file.write(str(latest_chapter_number))
With these additions, the script should
- Assistant
- User
make it check every minute
- Assistant
- User
can you explain meaning in this script of that import requests import time import json
- Assistant
Certainly!
-
import requests: This line imports therequestslibrary, which is a popular Python library for making HTTP requests. In this script, therequestslibrary is used to send HTTP requests to retrieve data from a webpage and make a POST request to the Discord webhook URL. -
import time: This line imports thetimemodule, which provides various time-related functions in Python. In this script, thetimemodule is used to introduce delays between checking for new chapters. Thesleep()function from thetimemodule is used to pause the script execution for a specified number of seconds. -
import json: This line imports thejsonmodule, which provides functions for working with JSON (JavaScript Object Notation) data in Python. In this script, thejsonmodule is used to serialize Python objects into JSON format for sending as the payload of a HTTP POST request to the Discord webhook URL.
-
- User
i have that script which is supposed to be similiar to my one. can you say is it working? import time from bs4 import BeautifulSoup from discord_webhook import DiscordWebhook import requests
WEBHOOK_URL = "https://discord.com/api/webhooks/1130786757609267241/I1Dv_QmHX_EwEVUHagrCWqfVmbXk3eqIGrDRhqCIBwaEjql-soQw88IJRMRUz1_amcZD"
def get_latest_chapter(): url = "https://mangalib.me/yu-yu-hakusho-digital-colored?section=chapters&ui=6398976" response = requests.get(url) soup = BeautifulSoup(response.text,'html.parser')
# The number and name of latest chapter are contained in first '.media-heading' class element latest_chapter_section = soup.find_all(class_='media-heading')[0] return latest_chapter_section.text.strip() - Assistant
This script seems to have a few errors and missing pieces of code. Here are the issues I can identify:
- Missing imports: The script is missing the necessary imports for the
DiscordEmbedandDiscordWebhookclasses. You need to include the following lines at the top of your script:
from discord_webhook import DiscordWebhook, DiscordEmbed-
Typo: In the
get_latest_chapter()function, the linereturn latest_chapter_section.text.strip()is usinglatest_chapter_sectionas the variable, but it should belatest_chapter. -
Variable names mismatch: In the while loop, there are some variables with mismatched names. For example,
latestChapterandcurrent_latest_chapshould be consistent throughout the code. You should update them to use the same naming convention. -
Typo: In the
notify_discord()function, the variable is assigned a value, but then it is referenced as in . It should be .
- Missing imports: The script is missing the necessary imports for the
- User
what wrong with dat? not working or im dumb import requests import time import json
WEBHOOK_URL = "https://discord.com/api/webhooks/1130786757609267241/I1Dv_QmHX_EwEVUHagrCWqfVmbXk3eqIGrDRhqCIBwaEjql-soQw88IJRMRUz1_amcZD" CHECK_INTERVAL = 60 # Check for new chapters every minute
- Assistant
Based on your updated script, it seems to be functioning correctly. The script retrieves the latest chapter details from the specified URL, compares it with the last known chapter number stored in the
last_known_chapter.txtfile, and sends a notification to Discord if there is a new chapter.To ensure the script executes properly, make sure you have a valid webhook URL and that the file
last_known_chapter.txtexists and contains an initial last known chapter number.The line
input('Press ENTER to exit')prompts the script to wait for user input before exiting. If you don't need this line, you can remove it.Additionally, make sure you have installed the necessary libraries by running
pip install requests jsonin your terminal/command prompt before executing the script.If you encounter any specific issues or error messages, please provide more details, and I'll be glad to assist you further.