[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [gettor/master] Start twitter responder



commit 1ca126906fcb0c216d5ec82df4b21d093873af00
Author: hiro <hiro@xxxxxxxxxxxxxx>
Date:   Wed Oct 9 19:23:46 2019 +0200

    Start twitter responder
---
 .gitignore                                     |   1 +
 gettor.conf.json                               |   7 +-
 gettor/services/twitter/twitterdm.py           |  91 ++++++++++++++++++++++++
 gettor/utils/settings.py                       |   9 ++-
 share/locale/smtp/i18n/en/LC_MESSAGES/en.mo    | Bin 1730 -> 0 bytes
 share/locale/smtp/i18n/en/LC_MESSAGES/en.po    |  57 ---------------
 share/locale/smtp/i18n/es/LC_MESSAGES/es.mo    | Bin 1811 -> 0 bytes
 share/locale/smtp/i18n/es/LC_MESSAGES/es.po    |  94 -------------------------
 share/locale/twitter/i18n/en/LC_MESSAGES/en.po |  55 ---------------
 share/locale/xmpp/i18n/en/LC_MESSAGES/en.mo    | Bin 340 -> 0 bytes
 share/locale/xmpp/i18n/en/LC_MESSAGES/en.po    |  55 ---------------
 share/locale/xmpp/i18n/en/LC_MESSAGES/es.mo    | Bin 340 -> 0 bytes
 share/locale/xmpp/i18n/es/LC_MESSAGES/es.mo    | Bin 342 -> 0 bytes
 share/locale/xmpp/i18n/es/LC_MESSAGES/es.po    |  22 ------
 14 files changed, 105 insertions(+), 286 deletions(-)

diff --git a/.gitignore b/.gitignore
index f00fa50..6c0bd3f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ _trial_temp
 gettor.pid
 csv
 .config
+gettor.conf.json
diff --git a/gettor.conf.json b/gettor.conf.json
index c7d6707..5c06e37 100644
--- a/gettor.conf.json
+++ b/gettor.conf.json
@@ -6,5 +6,10 @@
   "sendmail_interval": 10,
   "sendmail_addr": "gettor@xxxxxxxxxxxxxx",
   "sendmail_host": "localhost",
-  "sendmail_port": 587
+  "sendmail_port": 587,
+  "consumer_key": "",
+  "consumer_secret": "",
+  "access_key": "",
+  "access_secret": "",
+  "twitter_handle": "get_tor"
 }
diff --git a/gettor/services/twitter/twitterdm.py b/gettor/services/twitter/twitterdm.py
new file mode 100644
index 0000000..7f8543e
--- /dev/null
+++ b/gettor/services/twitter/twitterdm.py
@@ -0,0 +1,91 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of GetTor, a Tor Browser distribution system.
+#
+# :authors: isra <hiro@xxxxxxxxxxxxxx>
+#           see also AUTHORS file
+#
+# :copyright:   (c) 2008-2014, The Tor Project, Inc.
+#               (c) 2019, Hiro
+#
+# :license: This is Free Software. See LICENSE for license information.
+
+from __future__ import absolute_import
+
+import gettext
+import hashlib
+
+import configparser
+
+from twisted.internet import defer
+
+from ...utils.db import SQLite3 as DB
+from ...utils.commons import log
+from ...utils import strings
+
+class Twitterdm(object):
+    """
+    Class for sending twitter replies to `help` and `links` requests.
+    """
+    def __init__(self, settings):
+        """
+        Constructor. It opens and stores a connection to the database.
+        :dbname: reads from configs
+        """
+        self.settings = settings
+        dbname = self.settings.get("dbname")
+        consumer_key = self.settings.get("consumer_key")
+        consumer_secret = self.settings.get("consumer_secret")
+        access_key = self.settings.get("access_key")
+        access_secret = self.settings.get("access_secret")
+        twitter_handle = self.settings.get("twitter_handle")
+
+        self.conn = DB(dbname)
+
+    def get_interval(self):
+        """
+        Get time interval for service periodicity.
+
+        :return: time interval (float) in seconds.
+        """
+        return self.settings.get("twitter_interval")
+
+
+    def twitter_callback(self, message):
+        """
+        Callback invoked after a message has been sent.
+
+        :param message (string): Success details from the server.
+        """
+        log.info("Message sent successfully.")
+
+    def twitter_errback(self, error):
+        """
+        Errback if we don't/can't send the message.
+        """
+        log.debug("Could not send message.")
+        raise Error("{}".format(error))
+
+
+    def twitter_msg_list(self):
+
+
+
+    def twitterdm(self):
+        """
+        Send a twitter message for each message received. It creates a plain
+        text message, and sends it via twitter APIs
+
+        :param twitter_handle (str): email address of the recipient.
+        :param text (str): subject of the message.
+
+        :return: deferred whose callback/errback will handle the API execution
+        details.
+        """
+
+        log.debug("Retrieve list of messages")
+
+        log.debug("Creating message")
+
+
+        log.debug("Calling twitter APIs.")
diff --git a/gettor/utils/settings.py b/gettor/utils/settings.py
index 3e0a521..c849803 100644
--- a/gettor/utils/settings.py
+++ b/gettor/utils/settings.py
@@ -53,7 +53,7 @@ class Settings(object):
         if os.path.exists(self.filename):
             try:
                 with open(self.filename, 'r') as f:
-                    self._settings = json.load(f)
+                  self._settings = json.load(f)
             except:
                 pass
         else:
@@ -65,7 +65,12 @@ class Settings(object):
               "sendmail_interval": 10,
               "sendmail_addr": "gettor@xxxxxxxxxxxxxx",
               "sendmail_host": "localhost",
-              "sendmail_port": 587
+              "sendmail_port": 587,
+              "consumer_key": "",
+              "consumer_secret": "",
+              "access_key": "",
+              "access_secret": "",
+              "twitter_handle": "get_tor"
             }
 
     def get(self, key):
diff --git a/share/locale/smtp/i18n/en/LC_MESSAGES/en.mo b/share/locale/smtp/i18n/en/LC_MESSAGES/en.mo
deleted file mode 100644
index e686fcb..0000000
Binary files a/share/locale/smtp/i18n/en/LC_MESSAGES/en.mo and /dev/null differ
diff --git a/share/locale/smtp/i18n/en/LC_MESSAGES/en.po b/share/locale/smtp/i18n/en/LC_MESSAGES/en.po
deleted file mode 100644
index 13ea727..0000000
--- a/share/locale/smtp/i18n/en/LC_MESSAGES/en.po
+++ /dev/null
@@ -1,57 +0,0 @@
-domain "en"
-
-#: Links subject
-msgid "links_subject"
-msgstr "[GetTor] Links for your request"
-
-#: Mirrors subject
-msgid "mirrors_subject"
-msgstr "[GetTor] Mirrors"
-
-#: Help subject
-msgid "help_subject"
-msgstr "[GetTor] Help"
-
-# Unsupported locale subject
-msgid "unsupported_locale_subject"
-msgstr "[GetTor] Unsupported locale"
-
-# Unsupported locale message
-msgid "unsupported_locale_msg"
-msgstr "The locale you requested '%s' is not supported."
-
-#: Links message
-msgid "links_msg"
-msgstr "You requested Tor Browser for %s.\n\
-\n\
-You will need only one of the links below to download the bundle. If a link\n\
-does not work for you, try the next one.\n\
-\n\
-%s\n\
-\n\
-\n\
---\n\
-GetTor"
-
-#: Mirrors message
-msgid "mirrors_msg"
-msgstr "Hi! this is the GetTor robot.\n\
-\n\
-Thank you for your request. Attached to this email you will find\n\
-an updated list of mirrors of Tor Project's website."
-
-#: Help message
-msgid "help_msg"
-msgstr "Hi! This is the GetTor robot. I am here to help you download the\n\
-latest version of Tor Browser.\n\
-\n\
-Please reply to this message with one of the options below:\n\
-\n\
-    windows\n\
-    linux\n\
-    osx\n\
-    mirrors\n\
-\n\
-I will then send you the download instructions.\n\
-\n\
-If you are unsure, just send a blank reply to this message."
diff --git a/share/locale/smtp/i18n/es/LC_MESSAGES/es.mo b/share/locale/smtp/i18n/es/LC_MESSAGES/es.mo
deleted file mode 100644
index c21fe7b..0000000
Binary files a/share/locale/smtp/i18n/es/LC_MESSAGES/es.mo and /dev/null differ
diff --git a/share/locale/smtp/i18n/es/LC_MESSAGES/es.po b/share/locale/smtp/i18n/es/LC_MESSAGES/es.po
deleted file mode 100644
index bc4b5a8..0000000
--- a/share/locale/smtp/i18n/es/LC_MESSAGES/es.po
+++ /dev/null
@@ -1,94 +0,0 @@
-domain "es"
-
-#: Links subject
-msgid "links_subject"
-msgstr "[GetTor] Enlaces para tu petición"
-
-#: Links subject (PT)
-msgid "links_pt_subject"
-msgstr "[GetTor] Enlaces para tu petición"
-
-#: Help subject
-msgid "help_subject"
-msgstr "[GetTor] Ayuda"
-
-#: Delay subject
-msgid "delay_subject"
-msgstr "[GetTor] Mensaje de demora"
-
-# Unsupported locale subject
-msgid "unsupported_locale_subject"
-msgstr "[GetTor] Locale no soportado"
-
-# Unsupported locale message
-msgid "unsupported_locale_msg"
-msgstr "El locale especificado %s no está soportado."
-
-#: Links message
-msgid "links_msg"
-msgstr """Gracias por tu petición para %s-%s.\n\
-\n\
-Aquí están los links de descarga:\n\
-\n\
-===\n\
-%s\n\
-===\n\
-\n\
-===\n\
-Soporte:\n\
-===\n\
-\n\
-¿Aún necesitas ayuda? Si tienes dudas, problemas para conectarte a la\n\
-red Tor, o necesitas hablar con un humano, por favor contacta a nuestro\n\
-equipo de soporte a:\n\
-\n\
-    help@xxxxxxxxxxxxxxxxx\n\
-\n\
-Estamos listos para responder tus consultas en Inglés, Farsi, Chino,\n\
-Arábico, Francés y Español."""
-
-#: Links message (PT)
-msgid "links_pt_msg"
-msgstr """Gracias por tu petición para %s-%s.\n\
-\n\
-Aquí están los links de descarga:\n\
-\n\
-===\n\
-%s\n\
-===\n\
-Tip: Información sobre pluggable transports.\n\
-\n\
-===\n\
-Soporte:\n\
-===\n\
-\n\
-¿Aún necesitas ayuda? Si tienes dudas, problemas para conectarte a la\n\
-red Tor, o necesitas hablar con un humano, por favor contacta a nuestro\n\
-equipo de soporte a:\n\
-\n\
-    help@xxxxxxxxxxxxxxxxx\n\
-\n\
-Estamos listos para responder tus consultas en Inglés, Farsi, Chino,\n\
-Arábico, Francés y Español."""
-
-#: Help message
-msgid "help_msg"
-msgstr "Hola, este es el robot 'GetTor'.\n\
-\n\
-Gracias por tu petición. Estoy aquí para ayudarte a descargar la última\n\
-versión del Tor Browser Bundle.\n\
-\n\
-Por favor responde a este mensaje con una de las siguientes opciones:\n\
-\n\
-    windows\n\
-    linux\n\
-    osx\n\
-\n\
-Y te enviaré las instrucciones de descarga.\n\
-\n\
-Tip: Sólo envía una respuesta en blanco a este mensaje si no estás\n\
-seguro."
-
-#: Delay message
-msgid "delay_msg"
-msgstr "Mensaje de demora."
diff --git a/share/locale/twitter/i18n/en/LC_MESSAGES/en.po b/share/locale/twitter/i18n/en/LC_MESSAGES/en.po
deleted file mode 100644
index 46c2738..0000000
--- a/share/locale/twitter/i18n/en/LC_MESSAGES/en.po
+++ /dev/null
@@ -1,55 +0,0 @@
-domain "en"
-
-#: Links
-msgid "links"
-msgstr "You requested Tor Browser for %s.\n\
-\n\
-You will need only one of the links below to download the bundle. If a link\n\
-does not work for you, try the next one.\n\
-\n\
-%s"
-
-#: Mirrors message
-msgid "mirrors"
-msgstr "Hi! this is the GetTor robot.\n\
-\n\
-Thank you for your request. Below you will find an updated list of\n\
-mirrors of Tor Project's website.\n\
-\n\
-%s"
-
-#: Help
-msgid "help"
-msgstr "Hi! This is the GetTor robot. I am here to help you download the\n\
-latest version of Tor Browser.\n\
-\n\
-Please reply to this message with one of the options below:\n\
-\n\
-    windows\n\
-    linux\n\
-    osx\n\
-    mirrors\n\
-\n\
-I will then send you the download instructions."
-
-#: Mirrors unavailable message
-msgid "mirrors_unavailable"
-msgstr "Hello there! this is the 'GetTor' robot.\n\
-\n\
-I'm sorry, I can't send you mirrors right now, please try again later.\n\
-\n\
-Still need help? If you have any questions, trouble connecting to Tor\n\
-network, or need to talk to a human, please contact our support team at:\n\
-\n\
-    help@xxxxxxxxxxxxxxxxx\n\
-\n\
-We are ready to answer your queries in English, Farsi, Chinese, Arabic,\n\
-French and Spanish."
-
-#: Internal error
-msgid "internal_error"
-msgstr "Internal error"
-
-#: Internal error
-msgid "message_error"
-msgstr "Message too long."
diff --git a/share/locale/xmpp/i18n/en/LC_MESSAGES/en.mo b/share/locale/xmpp/i18n/en/LC_MESSAGES/en.mo
deleted file mode 100644
index 2480872..0000000
Binary files a/share/locale/xmpp/i18n/en/LC_MESSAGES/en.mo and /dev/null differ
diff --git a/share/locale/xmpp/i18n/en/LC_MESSAGES/en.po b/share/locale/xmpp/i18n/en/LC_MESSAGES/en.po
deleted file mode 100644
index 46c2738..0000000
--- a/share/locale/xmpp/i18n/en/LC_MESSAGES/en.po
+++ /dev/null
@@ -1,55 +0,0 @@
-domain "en"
-
-#: Links
-msgid "links"
-msgstr "You requested Tor Browser for %s.\n\
-\n\
-You will need only one of the links below to download the bundle. If a link\n\
-does not work for you, try the next one.\n\
-\n\
-%s"
-
-#: Mirrors message
-msgid "mirrors"
-msgstr "Hi! this is the GetTor robot.\n\
-\n\
-Thank you for your request. Below you will find an updated list of\n\
-mirrors of Tor Project's website.\n\
-\n\
-%s"
-
-#: Help
-msgid "help"
-msgstr "Hi! This is the GetTor robot. I am here to help you download the\n\
-latest version of Tor Browser.\n\
-\n\
-Please reply to this message with one of the options below:\n\
-\n\
-    windows\n\
-    linux\n\
-    osx\n\
-    mirrors\n\
-\n\
-I will then send you the download instructions."
-
-#: Mirrors unavailable message
-msgid "mirrors_unavailable"
-msgstr "Hello there! this is the 'GetTor' robot.\n\
-\n\
-I'm sorry, I can't send you mirrors right now, please try again later.\n\
-\n\
-Still need help? If you have any questions, trouble connecting to Tor\n\
-network, or need to talk to a human, please contact our support team at:\n\
-\n\
-    help@xxxxxxxxxxxxxxxxx\n\
-\n\
-We are ready to answer your queries in English, Farsi, Chinese, Arabic,\n\
-French and Spanish."
-
-#: Internal error
-msgid "internal_error"
-msgstr "Internal error"
-
-#: Internal error
-msgid "message_error"
-msgstr "Message too long."
diff --git a/share/locale/xmpp/i18n/en/LC_MESSAGES/es.mo b/share/locale/xmpp/i18n/en/LC_MESSAGES/es.mo
deleted file mode 100644
index 5896536..0000000
Binary files a/share/locale/xmpp/i18n/en/LC_MESSAGES/es.mo and /dev/null differ
diff --git a/share/locale/xmpp/i18n/es/LC_MESSAGES/es.mo b/share/locale/xmpp/i18n/es/LC_MESSAGES/es.mo
deleted file mode 100644
index d54f22c..0000000
Binary files a/share/locale/xmpp/i18n/es/LC_MESSAGES/es.mo and /dev/null differ
diff --git a/share/locale/xmpp/i18n/es/LC_MESSAGES/es.po b/share/locale/xmpp/i18n/es/LC_MESSAGES/es.po
deleted file mode 100644
index b6caac5..0000000
--- a/share/locale/xmpp/i18n/es/LC_MESSAGES/es.po
+++ /dev/null
@@ -1,22 +0,0 @@
-domain "es"
-
-#: Links
-msgid "links"
-msgstr "Enlaces para %s-%s:\n %s"
-
-#: Links
-msgid "links_pt"
-msgstr "Enlaces-PT para %s-%s:\n %s"
-
-#: Help
-msgid "help"
-msgstr "ayuda"
-
-#: Unsupported locale
-msgid "unsupported_lc"
-msgstr "Locale no soportado"
-
-#: Internal error
-msgid "internal_error"
-msgstr "Error interno"
-



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits