testing.py now shares Telepy class with TelepyShell

This commit is contained in:
chidea 2015-03-23 03:08:49 +09:00
parent 06c90ba9ab
commit 9f7f51a6d0
5 changed files with 17 additions and 27 deletions

View File

@ -1,5 +1,6 @@
class Chat(): class Chat():
def __init__(self): def __init__(self):
pass self._users = [] # users in this chatroom
pass def add_user(self, user):
self._users += user

View File

@ -1,6 +1,6 @@
import os, cmd import os, cmd
class telepyShell(cmd.Cmd): class TelepyShell(cmd.Cmd):
intro='Welcome to telepy interactive shell. Type help or ? for help.\n' intro='Welcome to telepy interactive shell. Type help or ? for help.\n'
prompt='>' prompt='>'

View File

@ -1,5 +1,11 @@
class User(): class User():
me = None
''' current connected user '''
friends = []
''' current connected user's friends '''
def __init__(self, uid): def __init__(self, uid):
self.uid = uid self.uid = uid

View File

@ -1,7 +1,7 @@
#CLI like interface #CLI like interface
import argparse, getopt, os, io, struct, mtproto import argparse, getopt, os, io, struct, mtproto
from classes.shell import telepyShell from classes.shell import TelepyShell
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser('telepy',description='Python implementation of telegram API.') parser = argparse.ArgumentParser('telepy',description='Python implementation of telegram API.')
@ -14,4 +14,4 @@ if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
if args.command is None: if args.command is None:
telepyShell().cmdloop() TelepyShell().cmdloop()

View File

@ -1,25 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os from classes.telepy import Telepy
import io
import struct
# Deal with py2 and py3 differences
try: # this only works in py2.7
import configparser
except ImportError:
import ConfigParser as configparser
import mtproto
telepy = Telepy()
# telepy._config #it's 'private' but can be accessed. Python's intelligent-programmer way. lol. Besides, we're in testing.py!
config = configparser.ConfigParser() # telepy._session
# Check if credentials is correctly loaded (when it doesn't read anything it returns []) # telepy._salt
if not config.read('credentials'):
print("File 'credentials' seems to not exist.")
exit(-1)
ip = config.get('App data', 'ip_address')
port = config.getint('App data', 'port')
Session = mtproto.Session(ip, port)
Session.create_auth_key()
future_salts = Session.method_call('get_future_salts', num=3)