Skip to content

Instantly share code, notes, and snippets.

@ag4ve
Created November 19, 2024 23:09
Show Gist options
  • Save ag4ve/53c6be287d0a856143f9ce6864f9f2c4 to your computer and use it in GitHub Desktop.
Save ag4ve/53c6be287d0a856143f9ce6864f9f2c4 to your computer and use it in GitHub Desktop.
First useful app from an AI - Microsoft copilot on iPhone
Got it! Here's a more detailed example of setting up a SOCKS proxy server in Python and fetching content from OneDrive using the `@content.downloadUrl`. This example uses the `pysocks` library for the proxy and `flask` for a simple web server.
First, install the necessary libraries:
```sh
pip install pysocks flask requests
```
Here's the complete code:
```python
import socket
import socks
import requests
from flask import Flask, request, jsonify
app = Flask(__name__)
# Set up SOCKS proxy
socks.set_default_proxy(socks.SOCKS5, "proxy_address", port)
socket.socket = socks.socksocket
# Function to fetch content from OneDrive
def fetch_from_onedrive(download_url):
response = requests.get(download_url)
if response.status_code == 200:
return response.content
else:
response.raise_for_status()
# Define a route for the proxy server
@app.route('/fetch', methods=['POST'])
def fetch():
data = request.get_json()
download_url = data.get('download_url')
try:
content = fetch_from_onedrive(download_url)
return jsonify({"content": content.decode('utf-8')}), 200
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
```
In this example:
- Replace `"proxy_address"` and `port` with your actual SOCKS proxy address and port.
- The `/fetch` endpoint expects a POST request with a JSON payload containing the `download_url`.
- The `fetch_from_onedrive` function uses this URL to download the content and returns it.
To run the server, save the code in a file, for example `proxy_server.py`, and execute it:
```sh
python proxy_server.py
```
Then, you can make a POST request to `http://your_server_ip:8080/fetch` with the `download_url` in the JSON body to fetch the content via your SOCKS proxy.
I hope this helps! 😊 Happy coding!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment