Sample Python usage?
#1307
-
Hi I want to write a simple Python code to submit to my remote server. Does anyone have a basic working code? The API pages do not seem to have any real example beside this, but this one does not show to connect to the server for real.
|
Beta Was this translation helpful? Give feedback.
Answered by
pirate
Jan 4, 2024
Replies: 1 comment 5 replies
-
There is no remote Python API currently, only a local one. You could write a small flask server like this to handle remote requests and pass them to the local ArchiveBox API as you see fit:
import os
from flask import Flask, request
app = Flask(__name__)
os.chdir('/path/to/archivebox/data')
from archivebox.config import setup_django
setup_django()
from archivebox.main import add
@app.route('/add', methods=['POST'])
def add_endpoint():
return add(**request.get_json())
if __name__ == '__main__':
app.run(debug=True)
import requests
# URL of the Flask server's /add endpoint
url = 'http://127.0.0.1:5000/add'
print(requests.post(url, json={
'urls': 'https://example.com\nhttps://example.com/2nd/url',
'tag': 'tag1,tag2,tag3',
'depth': 1,
'extract': 'singlefile,screenshot,dom,readability,media',
}).text) |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Windows is not really supported at all outside Docker.
A full REST API is still a work-in-progress and is not released yet (follow here for progress #496). Right now you can reuse the endpoints used by the Admin UI, which is what the ArchiveBox chrome extension does. (use browser devtools to see how the browser makes a request to the /add page for example)