Exemplo n.º 1
0
 def post(self):
     proxies = self.get_argument('proxies').split('\n')
     proxies = [
         proxy.strip() for proxy in list(set(proxies)) if proxy.strip()
     ]
     setting.set('worker.proxies', proxies, 'json')
     return self.get('需要重启工作进程或者程序才能使设置生效')
Exemplo n.º 2
0
def do_ap():
    import network
    import ubinascii
    import setting
    try:
        ap_if = network.WLAN(network.AP_IF)
        ap_if.active(True)
        mac = ubinascii.hexlify(network.WLAN().config('mac'), ':').decode()
        mac = mac[9:100]
        mac = mac.upper()
        ap_if.config(essid='ESP_' + mac, authmode=0)
        setting.set('opsmode', 'SoftAP')
    except:
        print('ERROR AP WIFI')
Exemplo n.º 3
0
def update():
    import ujson
    import setting
    import network
    try:
        FWnumber_me = setting.get('FWnumber')
        FWnumber_new = setting.get('FWnumberNew')
        print('FW me: ', FWnumber_me)
        print('FW new: ', FWnumber_new)
        if FWnumber_me != FWnumber_new:
            import wget
            import wifi
            import os
            FWurl = setting.get('FWurl')
            print('Download new FW: ', FWurl)
            if wifi.wait_sta(15):
                print('Start Update: ', FWurl)
                encoded = wget.get(FWurl).decode()
                path_spl = FWurl.split('/')
                protokoll = path_spl.pop(0)
                path_spl.pop(0)
                server = path_spl.pop(0)
                file = path_spl.pop()
                path = '/'.join(path_spl)
                dict = ujson.loads(encoded)
                file_list = dict['INSTALL']
                for file in file_list:
                    print('Update File : ' + protokoll + '//' + server + '/' +
                          path + '/' + file + ' >>> ' + file + '.tmp')
                    a = wget.get_file(
                        protokoll + '//' + server + '/' + path + '/' + file,
                        file + '.tmp')
                    fileSize = os.stat(file + '.tmp')
                    if fileSize[6] > 0:
                        os.rename(file + '.tmp', file)
                        print('Renamed file ' + file + '.tmp', file)
                    else:
                        print('Error updating file : ', file)
                        return
                setting.set('FWnumber', FWnumber_new)
                setting.set('FWversion', '{:04.2f}'.format(FWnumber_new / 100))
    except:
        print('ERROR in RepUpdate.update')
Exemplo n.º 4
0
def do_sta():
    import network
    import time
    import setting
    try:
        ssid = setting.get('ssid')
        password = setting.get('password')
        usedhcp = setting.get('usedhcp')
        ip = setting.get('ip')
        netmask = setting.get('netmask')
        gateway = setting.get('gateway')
        dnsserver = setting.get('dnsserver')
        sta_if = network.WLAN(network.STA_IF)
        sta_if.active(True)
        if usedhcp == 'no':
            sta_if.ifconfig((ip, netmask, gateway, dnsserver))
        sta_if.connect(ssid, password)
        setting.set('opsmode', 'client')
    except:
        print('ERROR STA WIFI')
Exemplo n.º 5
0
def new(VBat):
    import setting
    import ubinascii
    import network
    try:
        keypresses = setting.get('keypresses') + 1
        hwid = ubinascii.hexlify(network.WLAN().config('mac'),
                                 ':').decode().upper()
        setting.set('keypresses', keypresses)
        setting.set('hwid', hwid)
        setting.set('VBat', VBat)
        setting.set('RSSI', network.WLAN().status('rssi'))
    except:
        print('ERROR in RepUpdate.new')
Exemplo n.º 6
0
def is_sta():
    import network
    import setting
    sta_if = network.WLAN(network.STA_IF)
    if sta_if.isconnected():
        try:
            print(sta_if.ifconfig())
            setting.set('ip', sta_if.ifconfig()[0])
            setting.set('netmask', sta_if.ifconfig()[1])
            setting.set('gateway', sta_if.ifconfig()[2])
            setting.set('dnsserver', sta_if.ifconfig()[3])
        except:
            print('ERROR in is_sta')
    return (sta_if.isconnected())
Exemplo n.º 7
0
    def post(self):
        requests_per_minute = self.get_argument('requests-per-minute')
        setting.set('worker.requests-per-minute', requests_per_minute, int)

        local_object_duration_days = int(
            self.get_argument('local-object-duration'))
        local_object_duration = local_object_duration_days * 60 * 60 * 24
        setting.set('worker.local-object-duration', local_object_duration, int)

        broadcast_active_duration_days = int(
            self.get_argument('broadcast-active-duration'))
        broadcast_active_duration = broadcast_active_duration_days * 60 * 60 * 24
        setting.set('worker.broadcast-active-duration',
                    broadcast_active_duration, int)

        broadcast_incremental_backup = int(
            self.get_argument('broadcast-incremental-backup'))
        setting.set('worker.broadcast-incremental-backup',
                    broadcast_incremental_backup, bool)

        image_local_cache = int(self.get_argument('image-local-cache'))
        setting.set('worker.image-local-cache', image_local_cache, bool)

        return self.get('需要重启工作进程或者程序才能使设置生效')
Exemplo n.º 8
0
 async def on_command_error(self, ctx, error):
     if isinstance(error, commands.CommandInvokeError):
         log = "".join(
             traceback.format_exception(type(error), error,
                                        error.__traceback__))
         for page in pagify(log):
             asdf = f'```py\n{log}\n```'
         embed = discord.Embed(
             title=f'{ctx.command.qualified_name} 명령어에 에러가 발생하였습니다!',
             colour=discord.Colour.green())
         await ctx.send('에러 내용을 봇 관리진에게 보냈습니다! 빠른 시일내에 고치도록 하겠습니다!')
         await self.bot.get_user(int(setting.set().owner)
                                 ).send(embed=embed, content=asdf)
     elif isinstance(error, commands.CheckFailure):
         return await ctx.send(f'{ctx.author.mention}, 관리진 명령어를 사용하지 마세욧!')
     elif isinstance(error, commands.CommandNotFound):
         pass
Exemplo n.º 9
0
import random
import time
from urllib.request import urlopen, Request
import urllib
import bs4
from urllib.request import Request
import openpyxl
import re
import requests
from bs4 import BeautifulSoup
import datetime
import os
import sys
import json
from selenium import webdriver
set = setting.set()


app = discord.Client()
times = int(time.time())


maker = "480568196286644224"


@app.event
async def on_ready():
    print("login")
    print(app.user.name)
    print(app.user.id)
    print("------------------")
Exemplo n.º 10
0
def handleInterrupt(timer):    
    global interruptCounter
    global save_flag
    interruptCounter = interruptCounter + 1
    if interruptCounter == 1:        
        timeserver = setting.get('timeserver')
        if timeserver == '':
            setting.set('timeserver', 'pool.ntp.org') 
        webrepl.stop()
        RepUpdate.new(VBat)
                    
    if interruptCounter <= 5:
        print('<= 5 sec')
        if adc.read() < 200:
            timer.deinit()
            wifi.do_nothing()
            wifi.do_sta()
            print('Push Message')
            led_blink(10, 200, 0)
            if wifi.wait_sta(15):
                try:
                    import GenSasToken
                    import AzurePublish
                    import ubinascii
                    import network
                    mac = ubinascii.hexlify(network.WLAN().config('mac'),':').decode().upper()
                    UserJson = setting.get('userjson')
                    UserJson = UserJson.strip('\n')
                    UserJson = UserJson.strip('\r')
                    UserJson = UserJson.strip('\n')
                    UserJson = UserJson.strip(' ')
                    UserJson = UserJson.lstrip('{')
                    UserJson = UserJson.rstrip('}')
                    UserJson = UserJson.strip(' ')
                    msg = '{"UniqueID": "' + mac + '"'
                    if UserJson != '':
                        msg += ',' + UserJson
                    msg += '}'
                    gc.collect()
                    token = GenSasToken.now()
                    gc.collect()
                    encoded = AzurePublish.data(msg, token)
                except:
                    encoded = 'ERROR'
            else:
                encoded = 'ERROR'
            if encoded != 'ERROR':
                try:
                    dict = ujson.loads(encoded)
                    dict = dict["desired"]
                    setting.set('FWnumberNew', dict["FWnumber"])
                    setting.set('FWurl', dict["FWurl"])
                except:
                    print('ERROR TWIN MSG')
                led_blink(1, 1023, 0)
            else:
                print('ERROR Azure TX')
                led_blink(1, 0, 1023)
            time.sleep(2)    
            led_blink(1, 0, 0)
            RepUpdate.update()
            shutdown(save_flag)
    if interruptCounter == 5:
        print('5 sec')
        led_blink(1, 200, 200)
    if interruptCounter == 10:
        print('10 sec')
        if adc.read() < 200:
            print('WEB AP ...')
            timer.deinit()
            wifi.do_nothing()
            wifi.do_ap()
            led_blink(1, 0, 200)
            time.sleep(2)
            try:
                import webserver
                webserver.start()
            except:
                print('WEB Server Crash') 
            led_blink(1, 0, 0)
            shutdown()
        else:
            led_blink(3, 200, 200)
    if interruptCounter == 15:
        print('15 sec')
        if adc.read() < 200:
            print('WEB STA ...')
            timer.deinit()
            wifi.do_nothing()
            wifi.do_sta()
            led_blink(3, 0, 200)
            if wifi.wait_sta(15):
                try:
                    import webserver
                    webserver.start()
                except:
                    print('WEB Server Crash') 
            led_blink(1, 0, 0)
            shutdown()
        else:
            led_blink(10, 0, 511)
            print('Repair Time 120 sec')
            wifi.do_nothing()
            wifi.do_ap()
            wifi.do_sta()
            wifi.wait_sta(15)
            webrepl.start()
    if interruptCounter == 120:
        timer.deinit()
        print('120 sec')
        shutdown(False)
Exemplo n.º 11
0
from bs4 import BeautifulSoup
import requests, json, re, setting

historyPath, BunpouPath = setting.set(0)

with open(historyPath, 'r') as f:
    data = json.load(f)

i = len(data)
while True:
    html = requests.get('http://www.gutenberg.org/ebooks/{}'.format(i))
    soup = BeautifulSoup(html.text, 'html.parser')
    title = soup.select('#content > div.header > h1')
    title = title[0]
    title = re.split('[<>]', str(title))
    print(i, title[2])

    url = 'http://www.gutenberg.org/ebooks/{}.txt.utf-8'.format(str(i))

    with open(historyPath, 'r') as f:
        _d = json.load(f)
    jsonData = {}
    jsonData = _d
    if title[2] not in jsonData:
        jsonData[title[2]] = {"status": False, "url": url}
        with open(historyPath, 'w') as f:
            json.dump(jsonData, f, indent=4)

    i += 1
Exemplo n.º 12
0
 async def owner(ctx):
     if ctx.author.id == int(setting.set().owner):
         return True