Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scraper fixes #63

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rag/scraper/Scraper_master/scrape_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def download_pdf(self, url, filename):
- filename(str): Name of the PDF file
Returns: 1 on failure, file path on success.
"""
file_path = os.path.join(os.getcwd(), filename)
file_path = os.path.join(os.getcwd(), filename + ".pdf")
response = requests.get(url, headers=self.http_header)
if response.status_code == 200:
with open(file_path, 'wb') as f:
Expand All @@ -181,7 +181,7 @@ def download_pdf(self, url, filename):

# Override
def content_extract(self, filename, url, **kwargs):
if url[-4] == ".pdf":
if ".pdf" in url:
pdf_result = self.download_pdf(url, filename)
return pdf_result
else:
Expand Down
8 changes: 4 additions & 4 deletions rag/scraper/Scraper_master/scrape_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def content_extract(self, filename, url, **kwargs):
if response.status_code == 200:
with open(filename, 'wb') as f:
f.write(response.content)
print(f"Download completed successfully and saved as {self.root_filename}")
print(f"Download completed successfully and saved as {filename}")
else:
print(f"Failed to download the PDF. Status code: {response.status_code}")


# Example usage:
if __name__ == "__main__":
pdf_url = "http://example.com/path/to/your/pdf/file.pdf" # Replace with the actual PDF URL
pdf_saver = ScrapePdf(pdf_url) # Specify the filename to save as
pdf_saver.content_extract("name", pdf_url) # Start the download process
pdf_url = "pdflink" # Replace with the actual PDF URL
pdf_saver = ScrapePdf(pdf_url)
pdf_saver.content_extract("filename", pdf_url) # Change filename to save as and start the download process
3 changes: 2 additions & 1 deletion rag/scraper/Scraper_master/scrape_vid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from rag.scraper.Scraper_master.base_scraper import BaseScraper
from pytube import Playlist, YouTube
from pytubefix import Playlist, YouTube
import os
from utils import save_to_file

class ScrapeVid(BaseScraper):
def __init__(self, url, root_filename):
super().__init__(url)
Expand Down
Loading