Use aiograpi instead of instagrapi

This commit is contained in:
Oliver Hattshire 2025-10-27 00:32:58 -03:00
parent 742f5b4b21
commit e2a58b7216
5 changed files with 2062 additions and 19 deletions

View file

@ -26,7 +26,7 @@ custom_readme_tail: ''
debian_bundle: true
dependencies:
- slidge>=0.3,<0.4
- instagrapi>=2.2,<3
- aiograpi@git+https://github.com/subzeroid/aiograpi@965689e
dev_dependencies: []
intersphinx_mappings: []
lint_excludes: []
@ -42,8 +42,8 @@ repology: ''
requires_lottie: false
silo:
lib:
name: instagrapi
url: https://github.com/subzeroid/instagrapi
name: aiograpi
url: https://github.com/subzeroid/aiograpi
name: Instagram
url: https://instagram.com/
uv_sources: []

View file

@ -1,14 +1,15 @@
import asyncio
from instagrapi import Client
from instagrapi.exceptions import (
from aiograpi import Client
from aiograpi.exceptions import (
BadPassword,
ChallengeRequired,
FeedbackRequired,
TwoFactorRequired,
)
from slidge import BaseGateway, GatewayUser
from slidge import BaseGateway
from slidge.command.register import RegistrationType, TwoFactorNotRequired
from slidge.db import GatewayUser
from slixmpp import JID
from .utils import get_session_file
@ -35,7 +36,7 @@ class Gateway(BaseGateway):
session_file = get_session_file(user_jid.bare)
client = Client()
try:
_ = await asyncio.to_thread(client.login,
await client.login(
registration_form["username"],
registration_form["password"]
)
@ -50,22 +51,26 @@ class Gateway(BaseGateway):
except Exception as e:
raise ValueError("Could not authenticate: %s - %s", e, e.args)
else:
_ = await asyncio.to_thread(client.dump_settings, session_file)
await self._save_settings(client, session_file)
raise TwoFactorNotRequired
async def validate_two_factor_code(self, user: GatewayUser, code: str):
session_file = get_session_file(user.jid.bare)
client = self.instagram_client[user.jid.bare]
try:
if await asyncio.to_thread(client.login,
if await client.login(
user.legacy_module_data["username"],
user.legacy_module_data["password"],
verification_code=code):
if not await asyncio.to_thread(client.dump_settings, session_file):
raise IOError("Could not save session file: %s - %s", session_file)
await self._save_settings(client, session_file)
except ChallengeRequired as e:
raise ValueError("Browser Challenge Required", e, e.args)
except FeedbackRequired as e:
raise ValueError("Action moderated, account may be blocked", e, e.args)
except Exception as e:
raise ValueError("Could not authenticate: %s - %s", e, e.args)
@staticmethod
async def _save_settings(client: Client, session_file: str):
if not await asyncio.to_thread(client.dump_settings, session_file):
raise IOError("Could not save session file: %s - %s", session_file)

View file

@ -1,6 +1,6 @@
import asyncio
import instagrapi
import aiograpi
from slidge import BaseSession
from .utils import get_session_file
@ -12,14 +12,12 @@ class Session(BaseSession):
super().__init__(*a, **kw)
async def login(self):
client = instagrapi.Client()
self.client = aiograpi.Client()
session_file = get_session_file(self.user_jid.bare)
client.load_settings(session_file)
await asyncio.to_thread(client.login,
await asyncio.to_thread(self.client.load_settings, session_file)
await self.client.login(
self.user.legacy_module_data["username"],
self.user.legacy_module_data["password"])
self.log.info(
"Logged in: %s", str(self.user_jid.bare)
)
return f"Connected as '{self.client.user_id} <{self.client.username}>'"

View file

@ -13,8 +13,8 @@ requires-python = ">= 3.11"
keywords = ["xmpp", "chat", "instagram", "gateway", "bridge", "instant messaging"]
version = "0.0.0a1"
dependencies = [
"aiograpi@git+https://github.com/subzeroid/aiograpi@965689e",
"slidge>=0.3,<0.4",
"instagrapi>=2.2,<3",
]
[project.scripts]
@ -39,6 +39,9 @@ include = ["Insthidge"]
name = "pypi"
url = "https://pypi.org/simple"
[tool.uv.sources]
aiograpi = { git = "https://github.com/subzeroid/aiograpi", rev = "965689e" }
[tool.mypy]
files = ["Insthidge"]
check_untyped_defs = true

2037
uv.lock generated Normal file

File diff suppressed because it is too large Load diff