-
Notifications
You must be signed in to change notification settings - Fork 75
Add InstagrAPI script #281
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2a0dfae
Add instagrapi server scripts
erinhmclark 00b29db
Update documentaion for instagrapi api
erinhmclark 1466700
Small updates to docs, poetry.lock
erinhmclark f99dcc6
Minor updates
erinhmclark f715100
Add run_instagrapi_server.sh and update docs
erinhmclark b1a8792
Remove duplicate line
erinhmclark dd7d85b
Lock
erinhmclark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
# InstagrAPI Server | ||
|
||
The instagram API Extractor requires access to a running instance of the InstagrAPI server. | ||
We have a lightweight script with the endpoints required for our Instagram API Extractor module which you can run locally, or via Docker. | ||
|
||
|
||
|
||
⚠️ Warning: Remember that it's best not to use your own personal account for archiving. [Here's why](../installation/authentication.md#recommendations-for-authentication). | ||
## Quick Start: Using Docker | ||
|
||
We've provided a convenient shell script (`run_instagrapi_server.sh`) that simplifies the process of setting up and running the Instagrapi server in Docker. This script handles building the Docker image, setting up credentials, and starting the container. | ||
|
||
### 🔧 Running the script: | ||
|
||
Run this script either from the repository root or from within the `scripts/instagrapi_server` directory: | ||
|
||
```bash | ||
./scripts/instagrapi_server/run_instagrapi_server.sh | ||
``` | ||
|
||
This script will: | ||
- Prompt for your Instagram username and password. | ||
- Create the necessary `.env` file. | ||
- Build the Docker image. | ||
- Start the Docker container and authenticate with Instagram, creating a session automatically. | ||
|
||
### ⏱ To run the server again later: | ||
```bash | ||
docker start ig-instasrv | ||
``` | ||
|
||
### 🐛 Debugging: | ||
View logs: | ||
```bash | ||
docker logs ig-instasrv | ||
``` | ||
|
||
|
||
### Overview: How the Setup Works | ||
|
||
1. You enter your Instagram credentials in a local `.env` file | ||
2. You run the server **once locally** to generate a session file | ||
3. After that, you can choose to run the server again locally or inside Docker without needing to log in again | ||
|
||
--- | ||
|
||
## Optional: Manual / Local Setup | ||
|
||
If you'd prefer to run the server manually (without Docker), you can follow these steps: | ||
|
||
|
||
1. **Navigate to the server folder (and stay there for the rest of this guide)**: | ||
```bash | ||
cd scripts/instagrapi_server | ||
``` | ||
|
||
2. **Create a `secrets/` folder** (if it doesn't already exist in `scripts/instagrapi_server`): | ||
```bash | ||
mkdir -p secrets | ||
``` | ||
|
||
3. **Create a `.env` file** inside `secrets/` with your Instagram credentials: | ||
```dotenv | ||
INSTAGRAM_USERNAME="your_username" | ||
INSTAGRAM_PASSWORD="your_password" | ||
``` | ||
|
||
4. **Install dependencies** using the pyproject.toml file: | ||
|
||
```bash | ||
poetry install --no-root | ||
``` | ||
|
||
5. **Run the server locally**: | ||
```bash | ||
poetry run uvicorn src.instaserver:app --port 8000 | ||
``` | ||
|
||
6. **Watch for the message**: | ||
``` | ||
Login successful, session saved. | ||
``` | ||
|
||
✅ Your session is now saved to `secrets/instagrapi_session.json`. | ||
|
||
### To run it again locally: | ||
```bash | ||
poetry run uvicorn src.instaserver:app --port 8000 | ||
``` | ||
|
||
--- | ||
|
||
## Adding the API Endpoint to Auto Archiver | ||
|
||
The server should now be running within that session, and accessible at http://127.0.0.1:8000 | ||
|
||
You can set this in the Auto Archiver orchestration.yaml file like this: | ||
```yaml | ||
instagram_api_extractor: | ||
api_endpoint: http://127.0.0.1:8000 | ||
``` | ||
|
||
|
||
--- | ||
|
||
## 2. Running the Server Again | ||
|
||
Once the session file is created, you should be able to run the server without logging in again. | ||
|
||
### To run it locally (from scripts/instagrapi_server): | ||
```bash | ||
poetry run uvicorn src.instgrapinstance.instaserver:app --port 8000 | ||
``` | ||
|
||
--- | ||
|
||
## 3. Running via Docker (After Setup is Complete, either locally or via the script) | ||
|
||
Once the `instagrapi_session.json` and `.env` files are set up, you can pass them Docker and it should authenticate successfully. | ||
|
||
### 🔨 Build the Docker image manually: | ||
```bash | ||
docker build -t instagrapi-server . | ||
``` | ||
|
||
### ▶️ Run the container: | ||
```bash | ||
docker run -d \ | ||
--env-file secrets/.env \ | ||
-v "$(pwd)/secrets:/app/secrets" \ | ||
-p 8000:8000 \ | ||
--name ig-instasrv \ | ||
instagrapi-server | ||
``` | ||
|
||
This passes the /secrets/ directory to docker as well as the environment variables from the `.env` file. | ||
|
||
|
||
|
||
--- | ||
|
||
## 4. Optional Cleanup | ||
|
||
- **Stop the Docker container**: | ||
```bash | ||
docker stop ig-instasrv | ||
``` | ||
|
||
- **Remove the container**: | ||
```bash | ||
docker rm ig-instasrv | ||
``` | ||
|
||
- **Remove the Docker image**: | ||
```bash | ||
docker rmi instagrapi-server | ||
``` | ||
|
||
### ⏱ To run again later: | ||
```bash | ||
docker start ig-instasrv | ||
``` | ||
|
||
--- | ||
|
||
## Notes | ||
|
||
- Never share your `.env` or `instagrapi_session.json` — these contain sensitive login data. | ||
- If you want to reset your session, simply delete the `secrets/instagrapi_session.json` file and re-run the local server. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
secrets* | ||
*instagrapi_session.json |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this empty file needed? Perhaps it needs the
secrets
folder, or that might already be covered by the root gitignore