#!/usr/bin/python

import configparser
import json

from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError


# Reading Configs
config = configparser.ConfigParser()
config.read("E:/Games/cgi-bin/config.ini")

# Setting configuration values
api_id = config['Telegram']['api_id']
api_hash = config['Telegram']['api_hash']

api_hash = str(api_hash)

phone = config['Telegram']['phone']
username = config['Telegram']['username']


# Create the client and connect
client = TelegramClient(username, api_id, api_hash)
client.start()
print("Client Created")
# Ensure you're authorized
""" if not client.is_user_authorized():
    client.send_code_request(phone)
    try:
        client.sign_in(phone, input('Enter the code: '))
    except SessionPasswordNeededError:
        client.sign_in(password=input('Password: ')) """



print('Content-type:text/html')
print('\r\n\r\n')
print('<html>')
print('<head>')
print('<title>Hello World - First CGI Program</title>')
print('</head>')
print('<body>')

print('<h2>Hello World! This is my first CGI program</h2>')
print(api_hash)
print('</body>')
print('</html>')