Esempio n. 1
0
class LineAutoBot(object):
    def __init__(self, group):
        self.group = group
        self.__consts = Constants()
        self.__settings = Settings()
        self.__trans = Goslate()
        self.obj = json.loads(self.__consts.WANCAK_RAND.read())

    def katamutiara(self):
        count_rows = 0
        with open(os.path.join(os.path.dirname(__file__), self.__consts.PATH_KATAMUTIARA,\
            'kalimat.txt'),'r') as f:
            read_kalimat = f.readlines()
        with open(os.path.join(os.path.dirname(__file__), self.__consts.PATH_KATAMUTIARA,\
            'bagian.txt'),'r') as fs:
            read_bagian = fs.readlines()
            count_rows += sum(1 for _ in read_bagian)
        for x in range(0, count_rows + 1):
            j = randint(0, 110)
            join_data = "<bot-filsafat>" + "\n\n" + \
            read_kalimat[j] + "\n" + read_bagian[j]
            self.group.sendMessage(join_data)
            break
        return count_rows

    def translate(self, msg):
        detect = str(self.__trans.detect(msg))
        if 'id' in detect:
            send_translate = "<bot-translate> %s " % (self.__trans.translate(
                msg[14:], 'en'))
            send = self.group.sendMessage(send_translate)
        elif 'en' in detect:
            send_translate = "<bot-translate> %s " % (self.__trans.translate(
                msg[14:], 'id'))
            send = self.group.sendMessage(send_translate)
        else:
            send = self.group.sendMessage("<bot-translate> Gak ngerti!")

    # Running under Linux OS/Windows OS/Etc.
    def meme(self):
        self.__consts.WANCAK_RAND.close()
        url_image = str(self.obj['img'])
        urlreq = urllib2.Request(url_image,
                                 headers=self.__consts.CONST_REFERER)
        op = urllib2.urlopen(urlreq)
        sv_file = open(url_image[-38:], 'wb+')
        sv_file.write(str(op.read()))
        sv_file.close()
        self.group.sendImage(url_image[-38:])

    # Running under Linux OS Only.
    """
    def another_meme(self):
        self.__consts.WANCAK_RAND.close()
        url_image = str(self.obj['img'])
        header = 'Referer: http://1cak.com/'
        savedir = '/tmp/'
        cmd = "wget %s --header='%s' -P %s" % (url_image, header,savedir)
        get_image = os.system(cmd)
        #regex_url = re.search('http://cdn14.1cak.com/posts/(.*)', url_image).group(1)
        position = '%s%s' % (savedir, url_image[-38:])
        self.group.sendImage(position)
    """

    # convert youtube video to mp3.
    def youtubemp3(self, link, profile, mesg):
        try:
            if profile in mesg:
                sys.exit()
            else:
                url = "%s%s" % (self.__consts.YOUTUBE_CONVERTER, link)
                #header = 'Referer: http://youtubeinmp3.com/api/'
                #urlreq = urllib2.Request(url, headers=header)
                urlop = urllib2.urlopen(url)
                obj = json.loads(urlop.read())
                msg = "\
                \n [+] Judul: %s \
                \n[+] Link Download Mp3: %s" % (obj['title'], obj['link'])
                self.group.sendMessage(msg)
        except Exception:
            self.group.sendMessage(
                "[+] Sory bro!, URL youtube tidak valid! [+]")

    # download youtube video with the best quality.
    def youtube_download(self, url, profile, mesg):
        try:
            if profile in mesg:
                sys.exit()
            else:
                video = new(url)
                get_vid = video.getbest(preftype="mp4")
                #dl = get_vid.download(quiet=False, filepath=self.__settings.SITE_PATH)
                msg = " \
                \n [+] Judul Video: %s \n \
                \n[+] Uploader: %s \n \
                \n[+] Durasi: %s \n \
                \n[+] Link Download: %s%s.%s \n \
                \n[+] File video akan dihapus 1 menit lagi. \n \
                "                  % (video.title, video.author, video.duration, self.__settings.SITE_URL, \
                    video.title.replace(" ", "%20"), get_vid.extension)
                self.group.sendImageWithURL(video.thumb)
                self.group.sendMessage(msg)
        except Exception:
            self.group.sendMessage(
                "[+] Sory broh!, URL youtube tidak valid! [+]")

    def another_simsimi(self, msg, name, profile, mesg):
        if profile in mesg:
            sys.exit()
        else:
            acak = str(int(uniform(100000, 300000)))
            data = {'av': 5.2, 'ft': 1.0, 'lc': 'id', 'os': 'i', 'req': msg, \
            'tz': "Asia/Jakarta", 'uid': acak}
            url = self.__consts.SIMI_CHAT + urllib.urlencode(data)
            data = urllib2.urlopen(url)
            jawab = json.loads(data.read())
            bot_jawab = "<bot> @%s: %s" % (name, jawab['sentence_resp'].replace\
                ("simi", self.__settings.REPLACEMENT_CALL))
            self.group.sendMessage(bot_jawab)

    def jadwal_bioskop(self):
        nresults = urllib2.urlopen(self.__consts.MOVIE_PLAYING)
        obj = json.loads(nresults.read())
        nresults.close()
        total = 0
        msg = ''
        try:
            dt = "\n <bot> Misi permisi, ini film di bioskop yang lagi tayang ...\n"
            for out in obj:
                print ""
                show = "\n [+] Judul: %s \n [~] Link: %s \n" % (out['title'],
                                                                out['url'])
                join_data = ''.join(show.split("\t"))
                outmsg = "%s" % (join_data)
                msg += outmsg
                total += 1
            lastmsg = "\n [+] Total film baru tayang: %d film" % (total)
            self.group.sendMessage(dt + msg + lastmsg)
        except urllib2.HTTPError as err:
            print "Something went wrong!", err
        return total, msg
Esempio n. 2
0
class LineAutoBot(object):
    def __init__(self, group):
        self.group = group
        self.__consts = Constants()
        self.__settings = Settings()
        self.__trans = Goslate()
        self.obj = json.loads(self.__consts.WANCAK_RAND.read())

    def katamutiara(self):
        count_rows = 0
        with open(os.path.join(os.path.dirname(__file__), self.__consts.PATH_KATAMUTIARA,\
            'kalimat.txt'),'r') as f:
            read_kalimat = f.readlines()
        with open(os.path.join(os.path.dirname(__file__), self.__consts.PATH_KATAMUTIARA,\
            'bagian.txt'),'r') as fs:
            read_bagian = fs.readlines()
            count_rows+=sum(1 for _ in read_bagian)
        for x in range(0, count_rows+1):
            j = randint(0, 110)
            join_data = "<bot-filsafat>" + "\n\n" + \
            read_kalimat[j] + "\n" + read_bagian[j]
            self.group.sendMessage(join_data)
            break
        return count_rows

    def translate(self, msg):
        detect = str(self.__trans.detect(msg))
        if 'id' in detect:
            send_translate = "<bot-translate> %s " % (self.__trans.translate(msg[14:], 'en'))
            send = self.group.sendMessage(send_translate)
        elif 'en' in detect:
            send_translate = "<bot-translate> %s " % (self.__trans.translate(msg[14:], 'id'))
            send = self.group.sendMessage(send_translate)
        else:
            send = self.group.sendMessage("<bot-translate> Gak ngerti!")

    # Running under Linux OS/Windows OS/Etc.
    def meme(self):
        self.__consts.WANCAK_RAND.close()
        url_image = str(self.obj['img'])
        urlreq = urllib2.Request(url_image, headers=self.__consts.CONST_REFERER)
        op = urllib2.urlopen(urlreq)
        sv_file = open(url_image[-38:],'wb+')
        sv_file.write(str(op.read()))
        sv_file.close()
        self.group.sendImage(url_image[-38:])

    # Running under Linux OS Only.
    """
    def another_meme(self):
        self.__consts.WANCAK_RAND.close()
        url_image = str(self.obj['img'])
        header = 'Referer: http://1cak.com/'
        savedir = '/tmp/'
        cmd = "wget %s --header='%s' -P %s" % (url_image, header,savedir)
        get_image = os.system(cmd)
        #regex_url = re.search('http://cdn14.1cak.com/posts/(.*)', url_image).group(1)
        position = '%s%s' % (savedir, url_image[-38:])
        self.group.sendImage(position)
    """

    # convert youtube video to mp3.
    def youtubemp3(self, link, profile, mesg):
        try:
            if profile in mesg:
                sys.exit()
            else:
                url = "%s%s" % (self.__consts.YOUTUBE_CONVERTER, link)
                #header = 'Referer: http://youtubeinmp3.com/api/'
                #urlreq = urllib2.Request(url, headers=header)
                urlop = urllib2.urlopen(url)
                obj = json.loads(urlop.read())
                msg = "\
                \n [+] Judul: %s \
                \n[+] Link Download Mp3: %s" % (obj['title'], obj['link'])
                self.group.sendMessage(msg)
        except Exception: 
            self.group.sendMessage("[+] Sory bro!, URL youtube tidak valid! [+]")

    # download youtube video with the best quality.
    def youtube_download(self, url, profile, mesg):
        try:
            if profile in mesg:
                sys.exit()
            else:
                video = new(url)
                get_vid = video.getbest(preftype="mp4")
                #dl = get_vid.download(quiet=False, filepath=self.__settings.SITE_PATH)
                msg = " \
                \n [+] Judul Video: %s \n \
                \n[+] Uploader: %s \n \
                \n[+] Durasi: %s \n \
                \n[+] Link Download: %s%s.%s \n \
                \n[+] File video akan dihapus 1 menit lagi. \n \
                " % (video.title, video.author, video.duration, self.__settings.SITE_URL, \
                    video.title.replace(" ", "%20"), get_vid.extension)
                self.group.sendImageWithURL(video.thumb)
                self.group.sendMessage(msg)
        except Exception:
            self.group.sendMessage("[+] Sory broh!, URL youtube tidak valid! [+]")

    def another_simsimi(self, msg, name, profile, mesg):
        if profile in mesg:
            sys.exit()
        else:
            acak = str(int(uniform(100000,300000)))
            data = {'av': 5.2, 'ft': 1.0, 'lc': 'id', 'os': 'i', 'req': msg, \
            'tz': "Asia/Jakarta", 'uid': acak}
            url = self.__consts.SIMI_CHAT + urllib.urlencode(data)
            data = urllib2.urlopen(url)
            jawab = json.loads(data.read())
            bot_jawab = "<bot> @%s: %s" % (name, jawab['sentence_resp'].replace\
                ("simi", self.__settings.REPLACEMENT_CALL))
            self.group.sendMessage(bot_jawab)

    def jadwal_bioskop(self):
        nresults = urllib2.urlopen(self.__consts.MOVIE_PLAYING)
        obj = json.loads(nresults.read())
        nresults.close()
        total = 0
        msg = ''
        try:
            dt = "\n <bot> Misi permisi, ini film di bioskop yang lagi tayang ...\n"
            for out in obj:
                print ""
                show = "\n [+] Judul: %s \n [~] Link: %s \n" % (out['title'], out['url'])
                join_data = ''.join(show.split("\t"))
                outmsg = "%s" % (join_data)
                msg+=outmsg
                total+=1
            lastmsg = "\n [+] Total film baru tayang: %d film" % (total)
            self.group.sendMessage(dt+msg+lastmsg)
        except urllib2.HTTPError as err:
            print "Something went wrong!", err
        return total, msg