示例#1
0
    def update(self, ch, _user, _groups):
        if not os.path.isdir('/etc/jarvis'):
            self.send_now(ch, messages.ERROR_NOT_ENABLED('auto-update'))
            return

        self.send_now(ch, messages.UPDATING())
        subprocess.Popen(['/usr/bin/env', 'bash', '/etc/jarvis/bin/update'],
                         cwd='/etc/jarvis')
示例#2
0
    def get_weather(self, ch, user, _groups):
        token = os.environ.get('WORLD_WEATHER_TOKEN')
        if not token:
            self.send(ch, messages.ERROR_NOT_ENABLED('weather'))
            return

        place = LocationDal.read(user)

        rsp = requests.get(WEATHER_URL % (place, token)).json()['data']
        if 'error' in rsp:
            raise Exception(rsp)

        # API parsing
        astronomy = rsp['weather'][0]['astronomy'][0]
        city = rsp['nearest_area'][0]['areaName'][0]['value']
        current = rsp['current_condition'][0]
        description = current['weatherDesc'][0]['value'].lower()
        time = rsp['time_zone'][0]['localtime'].split(' ')[1]
        sunrise = astronomy['sunrise'].lstrip('0')
        sunset = astronomy['sunset'].lstrip('0')

        hour, minutes = time.split(':')
        hour, minutes = int(hour), int(minutes)
        if 5 <= hour < 12:
            greeting = 'Good morning'
        elif 12 <= hour < 17:
            greeting = 'Good afternoon'
        elif 17 <= hour < 23:
            greeting = 'Good evening'
        else:
            greeting = "You're up late"

        sunrise_tense = 'is'
        rise_hrs, rise_mins = helper.human_time_to_actual(sunrise)
        if hour > rise_hrs or (hour == rise_hrs and minutes == rise_mins):
            sunrise_tense = 'was'

        sunset_tense = 'will be'
        set_hrs, set_mins = helper.human_time_to_actual(sunset)
        if hour > set_hrs or (hour == set_hrs and minutes == set_mins):
            sunset_tense = 'was'

        self.send(
            ch,
            messages.PRINT_WEATHER(greeting, time, city, current['temp_C'],
                                   description, sunrise_tense, sunrise,
                                   sunset_tense, sunset))
示例#3
0
    def download(self, ch, _user, groups):
        url = groups[0].strip('<>')

        torrentfile = os.path.join(WATCH_DIR, '{}.torrent'.format(url))
        command = ['curl', '--globoff', url, '--output', torrentfile]
        if 'torrentday' in url[0]:
            cookie = os.environ.get('TORRENTDAY_COOKIE')
            if not cookie:
                self.send(ch, messages.ERROR_NOT_ENABLED('torrent'))
                return

            command.insert(1, '--cookie')
            command.insert(2, cookie)

        p = subprocess.Popen(command, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        code = p.wait()
        if code != 0:
            self.send(ch, messages.ERROR_ACCESS_URL())
            return

        self.send(ch, messages.WILL_STORE())
示例#4
0
    def help(self, ch):
        if not os.path.isdir(WATCH_DIR):
            self.send_now(ch, messages.ERROR_NOT_ENABLED('torrent'))
            return

        self.send_now(ch, __doc__.replace('\n', ' '))