Skip to content

Commit

Permalink
Merge pull request #77 from lazmond3/souji
Browse files Browse the repository at this point in the history
clean up
  • Loading branch information
lazmond3 authored Oct 27, 2022
2 parents 4471128 + c18148b commit b420fbc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
56 changes: 31 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
# ダンプ
https://www.instagram.com/p/CQdnVrkHZOC/?utm_source=ig_web_copy_link&__a=1 こちらのファイルを, instagram_multi_img.json こちらに
# 使い方 (how to use)

複数画像は、
```
edge_sidecar_to_children.edges[].node.display_url
```bash
# DEPENDS ON...
# - dict2obj (easier to access json object)
# - discord.py (bot)
# - requests (access to instagram)
# - boto3 (upload images and videos to s3)
# - youtube_dl (download youtube, tiktok)
# - ffmpeg (truncate video to sizing limitation for attachment)
# - black (format)
# - flake8 (linter)
# - autopep8 (linter)
# - isort (format)
# - beautifulsoup4 (parse html; for ask.fm)
# - pytest... (unit test)
# - elasticsearch, CMRESHandler (logging to elasticsearch)
pip3 -r requirements.txt

# WHEN RUN ON LOCAL(log output to stdout, else to elasticsearch)
IS_DEBUG=1 ENV=local TOKEN=$TOKEN python3 -m instagram_to_discord
```
あたりにあるっぽい.

# TODO
- [ ] env を一括でexport するようにする
- [ ] 後続で画像idxを指定するとき、s3を利用できていない。
- [ ] terraform のモジュールを検討する。
- [ ] テスト追加
- [ ] elasticsearch 導入
- [ ] 結合でsamplesを動かす
- [ ] ファイル名とか、パス名とか、一元管理する。
- [ ] サーバごとの差異を吸収する?
## 動作する機能 FUNCTIONS
- twitter の URL を post したあとに、自動でS3にアーカイブした動画URLを投稿する。(NSFWでない限り、自動でプレビューされる)
- twitter の URL を post したあとに、数字を post すると、当該インデックスの画像を投稿する(スマホで閲覧すると、プレビュー画像は1枚目しか表示されないため、他の画像への言及であることを強調したいときに使う)

# Usage
>- After posting a twitter URL, post the video URL archived to S3. (Unless it's NSFW, it will be previewed automatically by discord app)
>- If you post a number/numbers(index, comma seperated) after posting a twitter URL, the image(s) those index(indices) indicates will be posted. (When you view discord on a smartphone, only the first preview image is displayed, so use this when you want to emphasize that it is a reference to other images.)
```bash

pip3 -r requirements.txt
## DEPRECATED: important JSON paths
この項目は、instagram API の `__a=1` が廃止されたため、古くなりました。

> This item is obsolete due to the deprecation of __a=1 in the instagram API.
- `edge_sidecar_to_children.edges[].node.display_url`
- `edge_sidecar_to_children.edges[].node.display_url`

# execution
REDIS_PASS=$REDIS_PASS \
TOKEN=$DISCORD_BOT_TOKEN \
DEBUG=1 \
COOKIE_PATH=cookie2.txt \
python3 -m instagram_to_discord
```
7 changes: 4 additions & 3 deletions instagram_to_discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def env_check():
os.getenv("MID"),
os.getenv("SESSIONID"),
os.getenv("ENV"),
os.getenv("ES_HOST"),
os.getenv("ES_USER_NAME"),
os.getenv("ES_PASSWORD"),
# elasticsearch is not necessary.
# os.getenv("ES_HOST"),
# os.getenv("ES_USER_NAME"),
# os.getenv("ES_PASSWORD"),
]
):
logger.info("all environment variables are set.")
Expand Down
13 changes: 7 additions & 6 deletions instagram_to_discord/discord_event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ class DiscordMessageListener(discord.Client):
is_twitter_last = True

def __init__(self):
super().__init__()
# FIXME: `intents`` must be considered more carefully to retrieve message.content.
intents = discord.Intents.default()
intents.message_content = True
super().__init__(intents=intents)

async def on_ready(self):
logger.info(f"Logged on as {self.user}!")

async def on_message(self, message):
logger.info(
"Message from {0.author.display_name} in ({0.channel}): {0.content}".format(
message
)
)
content: str = message.content
channel: discord.TextChannel = message.channel
logger.info(
"Message from {0.author.display_name} in ({0.channel}): {0.content}".format(message)
)

if IS_DEBUG and "debug" not in channel.name:
return
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ aws-lambda-typing == 1.0.3
boto3
youtube_dl
ffmpeg
# nest_asyncio

beautifulsoup4

black
flake8
autopep8
isort

Flask
mypy
beautifulsoup4
pytest
pytest-mock
pytest-asyncio
Expand Down
2 changes: 1 addition & 1 deletion terraform/run/env/dev/dev.auto.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ecr_name = "discord-instagram-bot"
template_file_path = "../../../module/ecs/discord_pyhton.json.tpl" # main.tf からの相対パス

container_repository = "554506578892.dkr.ecr.ap-northeast-1.amazonaws.com/discord-instagram-bot"
container_tag = "1.1.0-ce64cc0"
container_tag = "1.1.0-047da49"

container_name = "discord-instagram-bot" # でいいのか?
# container_name = "nginx" # でいいのか?
Expand Down

0 comments on commit b420fbc

Please sign in to comment.