Commits

Anonymous committed 627d28a

added youtube and bot

Comments (0)

Files changed (4)

.DS_Store

Binary file removed.
 import photo_query
 from BeautifulSoup import BeautifulSoup
 from random import choice
+from youtube_query import get_video
+import ia_bot
 
 
 client = pytumblr.TumblrRestClient(
 
             elif "vidéo" in ev.arguments()[0]:
                 video = self.parse_ask("vidéo", ev.arguments()[0])
+                if video.startswith("http"):
+                    client.create_video("itschezleobitch", embed=video)
                 serv.privmsg("#chezleo", "Et voila : " + video)
 
             else:
-                serv.privmsg("#chezleo", u"Viens par ici : http://itschezleobitch.tumblr.com/")
+
+                serv.privmsg("#chezleo", unicode(ia_bot.responding(ev.arguments()[0])))
         response = self.parse(ev.arguments()[0])
         user = ev.source().split('!')[0]
         if response is not None:
             if len(resp) == 0:
                 return u"J'ai rien :("
             else:
-                return choice(photo_query.get_query(query))
+                return choice(resp)
         elif arg == "vidéo":
-            return u"C'est pas encore codé, mon créateur est une vraie feignasse"
+            resp = get_video(query)
+            if len(resp) == 0:
+                return u"J'ai rien :("
+            else:
+                return choice(resp)
 
     def is_video(self, response, url):
 
+# -*- coding: utf-8 -*-
+import requests
+url = "http://demo.vhost.pandorabots.com/pandora/talk?botid=bb9d8db85e36d4b9"
+
+
+def responding(message):
+    msg = []
+    for elem in message.split(" "):
+        if elem not in ["Britney", "Britney:"]:
+            msg.append(elem)
+    message = " ".join(msg)
+
+    resp = requests.post(url, params={'message': message})
+    resp = unicode(resp.text)
+    resp = resp.split("mctarek:</b>")[1].split("<br>")[0].strip()
+    if resp.startswith("<script"):
+        resp = resp.split("</script>")[1]
+    return resp
+# -*- coding: utf-8 -*-
+
+import requests
+import json
+endpoint = "https://gdata.youtube.com/feeds/api/videos"
+query = "Football"
+
+
+def get_video(query):
+    videos = []
+    response = requests.get(endpoint, params={'q': query, 'alt': 'json'})
+    if 'feed' in json.loads(response.content):
+        if 'entry' in json.loads(response.content)['feed']:
+            for elem in json.loads(response.content)['feed']['entry']:
+                videos.append(elem['link'][0]['href'])
+    return videos
+
+if __name__ == "__main__":
+    print get_video("Beyoncé et Rhianna")
+