Skip to content

Commit

Permalink
add .env example
Browse files Browse the repository at this point in the history
  • Loading branch information
richardokonicha committed Jan 19, 2021
1 parent 75c02cf commit c4502e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== fx-forwarder Config Vars
API_HASH = f36c296645a*****698ecb1e59e31b
API_ID = 127***5
CHATINPUT = -100143****109
CHATOUTPUT = -100142****638
20 changes: 20 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
from dotenv import load_dotenv
load_dotenv()

channel_input = os.getenv('CHATINPUT')
channel_input = [int(i) for i in channel_input.split(' ')] # dont
channel_output = int(os.getenv('CHATOUTPUT')) # dont

session = os.getenv("SESSION")
api_hash = os.getenv("API_HASH")
api_id = os.getenv("API_ID")

def save_session(client, session):
if session:
pass
else:
session_string = client.session.save()
env_string = f"SESSION = {session_string}"
with open(".env", "a") as env_file:
env_file.write(env_string)
14 changes: 2 additions & 12 deletions telethon_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@
from telethon.sessions import StringSession
import logging
from parser import pasig
import os
from dotenv import load_dotenv
load_dotenv()
from config import api_hash, api_id, channel_input, channel_output, session, save_session
# from util import bot_forward
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
level=logging.WARNING)

channel_input = os.getenv('CHATINPUT')
channel_input = [int(i) for i in channel_input.split(' ')] # dont
channel_output = int(os.getenv('CHATOUTPUT')) # dont

session = os.getenv("SESSION")
session = ''
api_hash = os.getenv("API_HASH")
api_id = os.getenv("API_ID")

# client = TelegramClient("BST_t", api_id, api_hash)
client = TelegramClient(StringSession(session), api_id, api_hash)

# client event handler on incoming new messages matching the regex filter from chat or channel
Expand All @@ -43,4 +32,5 @@ async def wakeup(event):
print(text)

client.start()
save_session(client, session)
client.run_until_disconnected()

0 comments on commit c4502e7

Please sign in to comment.