Commits

Gregory Petukhov committed 9d29b35

Small changes

Comments (0)

Files changed (1)

 
 def fetch_feed():
     """
-    Fetch and parse feed from habrahabr.ru. Return parsed publications.
+    Fetch and parse feeds.
     """
 
     result = []
     return result
 
 
+def send_message(items):
+    """
+    Compose and send message to XMPP conference.
+    """
+
+    client = setup_xmpp_client()
+    client.send(xmpp.Presence(to='%s/%s' % (settings.NOTIFY_ROOM, settings.XMPP_NICK)))
+
+    step = settings.LIMIT_PER_MESSAGE
+    for start in xrange(0, len(items), step):
+        message = []
+        for item in items[start:start + step]:
+            message.append(u'%s %s' % (item['title'], item['link']))
+        message = '\n'.join(message)
+        client.send(xmpp.Message(to=settings.NOTIFY_ROOM, typ='groupchat', body=message))
+        time.sleep(settings.MESSAGE_DELAY)
+
+
+def setup_xmpp_client():
+    """
+    Connect to xmpp server and authenticate.
+    """
+
+    jid = xmpp.protocol.JID(settings.XMPP_USER)
+    client = xmpp.Client(jid.getDomain(), debug=[])
+    if client.connect():
+        if client.auth(jid.getNode(), settings.XMPP_PASSWORD):
+            return client
+        else:
+            raise Exception('Could not authorize.')
+    else:
+        raise Exception('Could not connect.')
+
+
 def main():
     entries = fetch_feed()
     new_items = []
     logging.debug('Done')
 
 
-def send_message(items):
-    """
-    Compose and send message to XMPP conference.
-    """
-
-    client = setup_xmpp_client()
-    client.send(xmpp.Presence(to='%s/%s' % (settings.NOTIFY_ROOM, settings.XMPP_NICK)))
-
-    step = settings.LIMIT_PER_MESSAGE
-    for start in xrange(0, len(items), step):
-        message = []
-        for item in items[start:start + step]:
-            message.append(u'%s %s' % (item['title'], item['link']))
-        message = '\n'.join(message)
-        client.send(xmpp.Message(to=settings.NOTIFY_ROOM, typ='groupchat', body=message))
-        time.sleep(settings.MESSAGE_DELAY)
-
-
-def setup_xmpp_client():
-    """
-    Connect to xmpp server and authenticate.
-    """
-
-    jid = xmpp.protocol.JID(settings.XMPP_USER)
-    client = xmpp.Client(jid.getDomain(), debug=[])
-    if client.connect():
-        if client.auth(jid.getNode(), settings.XMPP_PASSWORD):
-            return client
-        else:
-            raise Exception('Could not authorize.')
-    else:
-        raise Exception('Could not connect.')
-
-
 if __name__ == "__main__":
     logging.basicConfig(level=logging.DEBUG)
     main()