Exemple #1
0
 def call(self, chat, author, q):
     if self.google_search_key is None:
         self.google_search_key = db.get_key('google_search')
     data = {
         'key': self.google_search_key,
         'cx': '009373417816394415455:i3e_omr58us',
         'q': q.encode('utf-8'),
         'searchType': 'image',
         'num': 1
     }
     response = urlfetch.fetch(
         url='https://www.googleapis.com/customsearch/v1?' +
         urllib.urlencode(data),
         method=urlfetch.GET)
     items = json.loads(response.content)['items']
     if len(items) == 0:
         telegram.send(chat, "Nothing found")
         return
     image = items[0]
     image_url = image['link']
     image_response = urlfetch.fetch(image_url, method=urlfetch.GET)
     if image_response.status_code != 200:
         telegram.send(chat, "Error retrieving image")
         return
     image_name = urlparse.urlsplit(image_url).path.split('/')[-1]
     telegram.send_image(chat, image_response.content, image_name,
                         image['mime'])
Exemple #2
0
def render_note():
    data = request.form
    name = data['note-name']
    key = data['key']
    text = os.popen('cat "notes/%s"' % name).read()
    if db.get_key(name) == key:
        text = utility.decrypt(text, key)
    return text
Exemple #3
0
 def find(self, q, start):
     if self.google_search_key is None:
         self.google_search_key = db.get_key('google_search')
     data = {
         'key': self.google_search_key,
         'cx': '009373417816394415455:i3e_omr58us',
         'q': q.encode('utf-8'),
         'searchType': 'image',
         'safe': 'medium',
         'num': 10
     }
     response = urlfetch.fetch(url='https://www.googleapis.com/customsearch/v1?' + urllib.urlencode(data), method=urlfetch.GET)
     return json.loads(response.content)['items']
Exemple #4
0
def send_image(recipient, image_content, image_name, image_type):
    global telegram_key
    global api_url

    if telegram_key is None:
        telegram_key = db.get_key('telegram')
    data = {
        'chat_id': recipient,
        'photo': MultipartParam('photo', value=image_content, filename=image_name, filetype=image_type)
    }
    payload, headers = multipart_encode(data)
    urlfetch.fetch(url=api_url + telegram_key + '/sendPhoto',
                   payload=''.join(payload),
                   method=urlfetch.POST,
                   headers={'Content-Type': headers['Content-Type']})
Exemple #5
0
def send(recipient, message):
    global telegram_key
    global api_url

    if recipient == 'console':
        print(message)
        return

    if telegram_key is None:
        telegram_key = db.get_key('telegram')
    data = {'chat_id': recipient, 'text': message}
    urlfetch.fetch(
        url=api_url + telegram_key + '/sendMessage',
        payload=urllib.urlencode(data),
        method=urlfetch.POST,
        headers={'Content-Type': 'application/x-www-form-urlencoded'})
Exemple #6
0
def send(recipient, message):
    global telegram_key
    global api_url

    if recipient == 'console':
        print(message)
        return

    if telegram_key is None:
        telegram_key = db.get_key('telegram')
    data = {
        'chat_id': recipient,
        'text': message
    }
    urlfetch.fetch(url=api_url + telegram_key + '/sendMessage',
                   payload=urllib.urlencode(data),
                   method=urlfetch.POST,
                   headers={'Content-Type': 'application/x-www-form-urlencoded'})
Exemple #7
0
def send_image(recipient, image_content, image_name, image_type):
    global telegram_key
    global api_url

    if telegram_key is None:
        telegram_key = db.get_key('telegram')
    data = {
        'chat_id':
        recipient,
        'photo':
        MultipartParam('photo',
                       value=image_content,
                       filename=image_name,
                       filetype=image_type)
    }
    payload, headers = multipart_encode(data)
    urlfetch.fetch(url=api_url + telegram_key + '/sendPhoto',
                   payload=''.join(payload),
                   method=urlfetch.POST,
                   headers={'Content-Type': headers['Content-Type']})
Exemple #8
0
 def call(self, chat, author, q):
     if self.google_search_key is None:
         self.google_search_key = db.get_key('google_search')
     data = {
         'key': self.google_search_key,
         'cx': '009373417816394415455:i3e_omr58us',
         'q': q.encode('utf-8'),
         'searchType': 'image',
         'num': 1
     }
     response = urlfetch.fetch(url='https://www.googleapis.com/customsearch/v1?' + urllib.urlencode(data), method=urlfetch.GET)
     items = json.loads(response.content)['items']
     if len(items) == 0:
         telegram.send(chat, "Nothing found")
         return
     image = items[0]
     image_url = image['link']
     image_response = urlfetch.fetch(image_url, method=urlfetch.GET)
     if image_response.status_code != 200:
         telegram.send(chat, "Error retrieving image")
         return
     image_name = urlparse.urlsplit(image_url).path.split('/')[-1]
     telegram.send_image(chat, image_response.content, image_name, image['mime'])
Exemple #9
0
        return "Оффлайн"
    elif client_status == 1:
        return "Поиск пиров..."
    elif client_status == 2:
        return "Подключен к сети"


"""
----------------------------------------------------------------------------------------------------
Ниже идет главный код, все backend функции писать выше
Все frontend функции писать ниже
----------------------------------------------------------------------------------------------------
"""

init()
public_key = db.get_key(get_config("wallet"))
exitt = 0
while exitt == 0:
    try:
        print("Аккаунт: %s\n----------" % public_key)
        print("Статус клиента: %s" % str(get_status()))
        print("IP: {0}".format(host))
        try:
            # Попытка вывести реальный ip если он найден.
            print("Real IP: {0}".format(real_host))
        except NameError:
            pass

        # |||Сделал для удобства и юольшей читабельности. Добавлен 5 пункт который прописан ниже.|||
        message = "1.Отправить сообщение\n" + \
                  "2.Посмотреть последнюю транзакцию\n" + \