Hardeepex / apiscrape

0 stars 0 forks source link

Sweep: I want to create a more robust web scraper for scraping the content from network tab apis #10

Closed Hardeepex closed 10 months ago

Hardeepex commented 10 months ago

I want you to build a best web scraper for scraping the content from Network tabs apis to csv and json format and also include the options if i want to upload the data on server or want to create a apis using that data. Create a plan how would you do

Checklist - [X] Modify `main.py` βœ“ https://github.com/Hardeepex/apiscrape/commit/9172d2b5e96d5d8a25c4e9c90a8aa114e575d3d4 [Edit](https://github.com/Hardeepex/apiscrape/edit/sweep/i_want_to_create_a_more_robust_web_scrap/main.py#L68-L102) - [X] Running GitHub Actions for `main.py` βœ“ [Edit](https://github.com/Hardeepex/apiscrape/edit/sweep/i_want_to_create_a_more_robust_web_scrap/main.py#L68-L102)
sweep-ai[bot] commented 10 months ago

πŸš€ Here's the PR! #11

See Sweep's progress at the progress dashboard!
πŸ’Ž Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: eda7327a58)
Install Sweep Configs: Pull Request

[!TIP] I'll email you at hardeep.ex@gmail.com when I complete this pull request!


Actions (click)

GitHub Actionsβœ“

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for 973b291
Checking main.py for syntax errors... βœ… main.py has no syntax errors! 1/1 βœ“
Checking main.py for syntax errors...
βœ… main.py has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: πŸ”Ž Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/Hardeepex/apiscrape/blob/973b291d013fb0b58bc308745d71dc88d78dbb75/main.py#L36-L102 https://github.com/Hardeepex/apiscrape/blob/973b291d013fb0b58bc308745d71dc88d78dbb75/main.py#L17-L35 https://github.com/Hardeepex/apiscrape/blob/973b291d013fb0b58bc308745d71dc88d78dbb75/main.py#L1-L16

Step 2: ⌨️ Coding

--- 
+++ 
@@ -1,4 +1,5 @@
 import requests
+import csv

 cookies = {
     'LocationIP': '99.235.82.251',
@@ -71,6 +72,19 @@
     response_json = response.json()
     # Organize the data in a specific format
     organized_data = organize_data(response_json)
+    # Save the organized data in JSON format
+    try:
+        with open('data.json', 'w') as json_file:
+            json.dump(organized_data, json_file)
+    except Exception as e:
+        print('An error occurred while writing to JSON:', e)
+    # Save the organized data in CSV format
+    try:
+        with open('data.csv', 'w', newline='') as csv_file:
+            csv_writer = csv.writer(csv_file)
+            csv_writer.writerows(organized_data.items())
+    except Exception as e:
+        print('An error occurred while writing to CSV:', e)
     return organized_data

 def organize_data(data):
@@ -101,3 +115,27 @@
         json.dump(response.json(), file)
 else:
     print("Request failed with status code:", response.status_code)
+
+def upload_data_to_server(file_path, server_url):
+    try:
+        with open(file_path, 'rb') as data_file:
+            files = {'file': (file_path, data_file)}
+            response = requests.post(server_url, files=files)
+            response.raise_for_status()
+            print('File uploaded successfully.')
+    except Exception as e:
+        print('An error occurred during file upload:', e)
+
+from flask import Flask, jsonify
+
+app = Flask(__name__)
+
+@app.route('/api/data', methods=['GET'])
+def create_api(file_path):
+    try:
+        with open(file_path, 'r') as data_file:
+            data = json.load(data_file)
+            return jsonify(data)
+    except Exception as e:
+        print('An error occurred while creating the API:', e)
+        return jsonify({'error': 'An error occurred while loading data'}), 500

Ran GitHub Actions for 9172d2b5e96d5d8a25c4e9c90a8aa114e575d3d4:


Step 3: πŸ” Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/i_want_to_create_a_more_robust_web_scrap.


πŸŽ‰ Latest improvements to Sweep:


πŸ’‘ To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord