diff --git a/README.md b/README.md index 64fc351..25ca4ee 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ $ pip3 install -U -r requirements.txt |------------- | ------------- | `API_ID` (required) | Telegram api_id obtained from https://my.telegram.org/apps. | `API_HASH` (required) | Telegram api_hash obtained from https://my.telegram.org/apps. -| `CHAT_ID` (required) | Id of the telegram channel (or chat) to be indexed. +| `CHAT_ID` (required) | Id of the telegram channel (or chat) to be indexed. Separate id's with space if you want to index more than one channel. | `SESSION_STRING` (required) | String obtained by running `$ python3 app/generate_session_string.py`. (Login with the telegram account which is a participant of the given channel (or chat). | `PORT` (optional) | Port on which app should listen to, defaults to 8080. | `HOST` (optional) | Host name on which app should listen to, defaults to 0.0.0.0. diff --git a/app.json b/app.json index f72ffa1..4024beb 100644 --- a/app.json +++ b/app.json @@ -13,7 +13,7 @@ "value":"" }, "CHAT_ID":{ - "description":"Id of the telegram channel (or chat) to be indexed.", + "description":"Id of the telegram channel (or chat) to be indexed. Separate id's with space if you want to index more than one channel.", "value":"" }, "SESSION_STRING":{ diff --git a/app/__main__.py b/app/__main__.py index 8485b6c..80d3dbe 100644 --- a/app/__main__.py +++ b/app/__main__.py @@ -16,6 +16,7 @@ TEMPLATES_ROOT = pathlib.Path(__file__).parent / 'templates' client = Client(session_string, api_id, api_hash) logging.basicConfig(level=logging.DEBUG if debug else logging.INFO) logging.getLogger("telethon").setLevel(logging.INFO if debug else logging.ERROR) +logging.getLogger("aiohttp").setLevel(logging.INFO if debug else logging.ERROR) log = logging.getLogger("tg-index") diff --git a/app/config.py b/app/config.py index 2b89cac..8732d90 100644 --- a/app/config.py +++ b/app/config.py @@ -19,7 +19,8 @@ except (KeyError, ValueError): sys.exit(1) try: - chat_id = int(os.environ["CHAT_ID"]) + chat_id_raw = os.environ["CHAT_ID"] + chat_ids = [int(chat_id) for chat_id in chat_id_raw.split(' ')] except (KeyError, ValueError): print("Please set the CHAT_ID environment variable correctly") sys.exit(1) diff --git a/app/routes.py b/app/routes.py index 58e3d62..ba05629 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,15 +1,22 @@ from aiohttp import web +from config import chat_ids + def setup_routes(app, handler): h = handler - app.add_routes( - [ - web.get('/', h.index, name='index'), - web.get(r"/{id:\d+}/view", h.info, name='info'), - web.get(r"/{id:\d+}/download", h.download_get), - web.head(r"/{id:\d+}/download", h.download_head), - web.get(r"/{id:\d+}/thumbnail", h.thumbnail_get), - web.head(r"/{id:\d+}/thumbnail", h.thumbnail_head), + routes = [ + web.get('/', h.home, name='home') + ] + for chat_id in chat_ids: + p = f"/{chat_id}" + r = [ + web.get(p, h.index), + web.get(p + r"/{id:\d+}/view", h.info), + web.get(p + r"/{id:\d+}/download", h.download_get), + web.head(p + r"/{id:\d+}/download", h.download_head), + web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get), + web.head(p + r"/{id:\d+}/thumbnail", h.thumbnail_head), ] - ) + routes += r + app.add_routes(routes) diff --git a/app/templates/home.html b/app/templates/home.html new file mode 100644 index 0000000..ebc4e12 --- /dev/null +++ b/app/templates/home.html @@ -0,0 +1,12 @@ +{% include 'header.html' %} + +

+ Available Sources +

+
+ {% for chat in chats %} +
  • {{chat.name}}
  • + {% endfor %} +
    + +{% include 'footer.html' %} diff --git a/app/templates/index.html b/app/templates/index.html index e726bbb..fe91a58 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,8 +1,18 @@ {% include 'header.html' %} -
    - - -
    + +
    +
    +

    {{name}}

    +
    + +
    +
    + + +
    +
    + +
    @@ -21,7 +31,7 @@ {{item.file_id}} {{item.media}} {{item.mime_type}} - {{item.insight}} + {{item.insight}} {{item.date}} {{item.size}} diff --git a/app/templates/info.html b/app/templates/info.html index 581c0dd..300ef88 100644 --- a/app/templates/info.html +++ b/app/templates/info.html @@ -9,13 +9,13 @@
    {% if media.image %} - {{name}} + {{name}} {% elif media.video %} -