Beispiel #1
0
async def download_url(url, file_name):
    start = int(time.time())
    downloader = Downloader(url=url)
    end = int(time.time())
    times = await time_parser(start, end)
    downlaoded = f'⬇️ Downloaded `{file_name}` in {times}'
    downlaoded += f'\n🗂 File name: {file_name}'
    size = os.path.getsize(downloader.file_name)
    if size > 1024000000:
        file_size = round(size / 1024000000, 3)
        downlaoded += '\n💿 File size: `' + str(file_size) + ' GB`\n'
    elif 1024000 < size < 1024000000:
        file_size = round(size / 1024000, 3)
        downlaoded += '\n💿 File size: `' + str(file_size) + ' MB`\n'
    elif 1024 < size < 1024000:
        file_size = round(size / 1024, 3)
        downlaoded += '\n💿 File size: `' + str(file_size) + ' KB`\n'
    elif size < 1024:
        file_size = round(size, 3)
        downlaoded += '\n💿 File size: `' + str(file_size) + ' Byte`\n'

    try:
        os.rename(downloader.file_name, 'skynoid/downloads/' + file_name)
    except OSError:
        return 'Failed to download file\nInvaild file name!'
    return downlaoded
async def download_url(url, file_name):
    start = int(time.time())
    downloader = Downloader(url=url)
    end = int(time.time())
    times = await time_parser(start, end)
    downlaoded = f"⬇️ Downloaded `{file_name}` in {times}"
    downlaoded += "\n🗂 File name: {}".format(file_name)
    size = os.path.getsize(downloader.file_name)
    if size > 1024000000:
        file_size = round(size / 1024000000, 3)
        downlaoded += "\n💿 File size: `" + str(file_size) + " GB`\n"
    elif 1024000 < size < 1024000000:
        file_size = round(size / 1024000, 3)
        downlaoded += "\n💿 File size: `" + str(file_size) + " MB`\n"
    elif 1024 < size < 1024000:
        file_size = round(size / 1024, 3)
        downlaoded += "\n💿 File size: `" + str(file_size) + " KB`\n"
    elif size < 1024:
        file_size = round(size, 3)
        downlaoded += "\n💿 File size: `" + str(file_size) + " Byte`\n"

    try:
        os.rename(downloader.file_name, "nana/downloads/" + file_name)
    except OSError:
        return "Failed to download file\nInvaild file name!"
    return downlaoded
Beispiel #3
0
async def download_from_url(url: str, file_name: str) -> str:
    """
    Download files from URL
    """
    start = datetime.now()
    downloader = Downloader(url=url)
    end = datetime.now()
    duration = (end - start).seconds
    os.rename(downloader.file_name, file_name)
    status = f"Downloaded `{file_name}` in {duration} seconds."
    return status
Beispiel #4
0
def initialize():
    """
    Initial loading and preparing
    """
    Downloader(url="https://raw.githubusercontent.com/XiaomiFirmwareUpdater/"
                   "xiaomi-flashable-firmware-creator.py/py/" +
               "xiaomi_flashable_firmware_creator/create_flashable_firmware.py")
    with open('devices/stable_devices.yml', 'r') as stable_json:
        stable_devices = yaml.load(stable_json, Loader=yaml.CLoader)
    open('log', 'w').close()
    all_stable = yaml.load(get(
        "https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/" +
        "stable_recovery/stable_recovery.yml").text, Loader=yaml.CLoader)
    names = yaml.load(get(
        "https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/" +
        "devices/names.yml").text, Loader=yaml.CLoader)
    return stable_devices, all_stable, names
Beispiel #5
0
def initialize():
    """
    Initial loading and preparing
    """
    Downloader(
        url="https://raw.githubusercontent.com/XiaomiFirmwareUpdater/"
        "xiaomi-flashable-firmware-creator.py/py/" +
        "xiaomi_flashable_firmware_creator/create_flashable_firmware.py")
    with open('devices/stable_devices.json', 'r') as stable_json:
        stable_devices = json.load(stable_json)
    with open('devices/weekly_devices.json', 'r') as weekly_json:
        weekly_devices = json.load(weekly_json)
    open('log', 'w').close()
    all_stable = get(
        "https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/"
        + "stable_recovery/stable_recovery.json").json()
    all_weekly = get(
        "https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/"
        + "weekly_recovery/weekly_recovery.json").json()
    return stable_devices, weekly_devices, all_stable, all_weekly
Beispiel #6
0
def is_redis_alive():
    try:
        REDIS.ping()
        return True
    except BaseException:
        return False


# Download binaries for gen_direct_links module, give correct perms
if not os.path.exists('bin'):
    os.mkdir('bin')

url1 = 'https://raw.githubusercontent.com/yshalsager/megadown/master/megadown'
url2 = 'https://raw.githubusercontent.com/yshalsager/cmrudl.py/master/cmrudl.py'

dl1 = Downloader(url=url1, filename="bin/megadown")
dl1 = Downloader(url=url1, filename="bin/cmrudl")

os.chmod('bin/megadown', 0o755)
os.chmod('bin/cmrudl', 0o755)

# Global Variables
COUNT_MSG = 0
BRAIN_CHECKER = []
USERS = {}
COUNT_PM = {}
LASTMSG = {}
ENABLE_KILLME = True
CMD_HELP = {}
AFKREASON = "no reason"
ZALG_LIST = [[
Beispiel #7
0
            log.write(var + '|' + branch + '|' + model + '|' + codename + '|' +
                      version + '|' + android + '|' + file + '|' + zip_size +
                      '|' + md5 + '\n')
        except NameError:
            pass


GIT_OAUTH_TOKEN = environ['XFU']
gh = GitHub(token=GIT_OAUTH_TOKEN)

bottoken = environ['bottoken']
telegram_chat = "@XiaomiFirmwareUpdater"
work_dir = getcwd()

Downloader(
    url=
    "https://github.com/XiaomiFirmwareUpdater/xiaomi-flashable-firmware-creator.py/raw/py/"
    + "create_flashable_firmware.py")

with open('devices/stable_devices.json', 'r') as s:
    stable_devices = json.load(s)
with open('devices/weekly_devices.json', 'r') as w:
    weekly_devices = json.load(w)

arb_devices = [
    'nitrogen', 'nitrogen_global', 'sakura', 'sakura_india_global', 'wayne',
    'whyred', 'whyred_global'
]

open('log', 'w').close()

stable_all = json.loads(
Beispiel #8
0
def main():
    """ XiaomiFirmwareUpdater """
    branch = ''
    devices = ''
    devices_all = None
    stable_devices, weekly_devices, all_stable, all_weekly = initialize()
    for variant in VARIANTS:
        if path.exists(variant + '.yml'):
            rename(variant + '.yml', variant + '_old.yml')
        if variant == 'stable':
            devices_all = all_stable
            devices = stable_devices
            branch = STABLE
        elif variant == "weekly":
            devices_all = all_weekly
            devices = weekly_devices
            branch = WEEKLY
        for i in devices_all:
            codename = str(i["codename"])
            if codename in devices:
                try:
                    branch.update({
                        codename:
                        str(i["filename"]).split('_')[1] + '_' +
                        str(i["filename"]).split('_')[2]
                    })
                except IndexError:
                    continue
        with open(variant + '.yml', 'w') as output:
            yaml.dump(branch, output, Dumper=yaml.CDumper)

        # diff
        changes = diff(variant)
        print(variant + " changes:\n" + str(changes))
        with open(variant + '_changes', 'w') as output:
            output.write(str(changes))
        if not changes:
            continue
        to_update = [list(i.keys())[0] for i in changes]
        # get links
        links = {}
        for codename in to_update:
            try:
                links.update({
                    codename: [
                        i["download"] for i in devices_all
                        if i["codename"] == codename
                    ][0]
                })
            except IndexError:
                continue
        # download and generate fw
        for codename, url in links.items():
            file = url.split('/')[-1]
            version = file.split("_")[2]
            # check if rom is rolled-back
            old_data = yaml.load(get(
                "https://raw.githubusercontent.com/XiaomiFirmwareUpdater/" +
                "xiaomifirmwareupdater.github.io/master/data/devices/" +
                f"full/{codename.split('_')[0]}.yml").text,
                                 Loader=yaml.CLoader)
            if old_data == {404: 'Not Found'}:
                print(f"Working on {codename} for the first time!")
                old_data = []
            region = set_region(file)
            if 'V' in version:
                all_versions = [i for i in old_data if i['branch'] == 'stable']
            else:
                all_versions = [i for i in old_data if i['branch'] == 'weekly']
            check = [
                i for i in all_versions
                if i['versions']['miui'] == version and i['region'] == region
            ]
            if check:
                print(f"{codename}: {version} is rolled back ROM, skipping!")
                continue
            # start working
            print("Starting download " + file)
            downloader = Downloader(url=url)
            if downloader.is_running:
                sleep(2)
            print('File downloaded to %s' % downloader.file_name)
            if codename in ARB_DEVICES:
                subprocess.call(
                    ['python3', 'create_flashable_firmware.py', '-F', file])
                subprocess.call(
                    ['python3', 'create_flashable_firmware.py', '-N', file])
            else:
                subprocess.call(
                    ['python3', 'create_flashable_firmware.py', '-F', file])
            remove(file)
            # upload to OSDN/GitHub
            today = str(date.today().strftime('%d.%m.%Y'))
            for file in glob("fw_*.zip"):
                codename = str(file).split("_")[1]
                version = set_version(file)
                upload_fw(file, version, codename, today, variant)
            for file in glob("fw-non-arb_*.zip"):
                codename = str(file).split("_")[1]
                version = set_version(file)
                upload_non_arb(file, version, codename)
            # log the made files
            stable = [f for f in glob("fw*.zip") if "_V1" in f]
            for file in stable:
                branch = 'stable'
                log_new(file, branch)
            weekly = [f for f in glob("fw*.zip") if "_V1" not in f]
            for file in weekly:
                branch = 'weekly'
                log_new(file, branch)
            for file in glob("*.zip"):
                remove(file)
    git_commit_push()
    update_site()
    post_updates()
Beispiel #9
0
def main():
    """ XiaomiFirmwareUpdater """
    branch = ''
    devices = ''
    devices_all = None
    stable_devices, weekly_devices, all_stable, all_weekly = initialize()
    for variant in VARIANTS:
        if path.exists(variant + '.json'):
            rename(variant + '.json', variant + '_old.json')
        if variant == 'stable':
            devices_all = all_stable
            devices = stable_devices
            branch = STABLE
        elif variant == "weekly":
            devices_all = all_weekly
            devices = weekly_devices
            branch = WEEKLY
        for i in devices_all:
            codename = str(i["codename"])
            if codename in devices:
                try:
                    branch.update({
                        codename:
                        str(i["filename"]).split('_')[1] + '_' +
                        str(i["filename"]).split('_')[2]
                    })
                except IndexError:
                    continue
        with open(variant + '.json', 'w') as output:
            json.dump(branch, output, indent=1)

        # diff
        with open(variant + '_old.json',
                  'r') as old, open(variant + '.json', 'r') as new:
            diff = difflib.unified_diff(old.readlines(),
                                        new.readlines(),
                                        fromfile=f'{variant}_old.json',
                                        tofile=f'{variant}.json')
        changes = []
        for line in diff:
            if line.startswith('+'):
                changes.append(str(line).strip().replace("}", "") + '\n')
        new = ''.join(changes[1:]).replace("+", "")
        print(variant + " changes:\n" + new)
        with open(variant + '_changes', 'w') as output:
            output.write(new)
        # get links
        links = {}
        for i in changes[1:]:
            for info in devices_all:
                try:
                    if str(info["filename"]).split('_')[1] + '_' + \
                            str(info["filename"]).split('_')[2] == \
                            str(i).split('"')[3]:
                        links.update({str(i).split('"')[1]: info["download"]})
                except IndexError:
                    continue
        # download and generate fw
        for codename, url in links.items():
            file = url.split('/')[-1]
            version = file.split("_")[2]
            # check if rom is rolled-back
            try:
                old_data = get(
                    "https://raw.githubusercontent.com/XiaomiFirmwareUpdater/"
                    + "xiaomifirmwareupdater.github.io/master/data/devices/" +
                    f"full/{codename.split('_')[0]}.json").json()
            except json.decoder.JSONDecodeError:
                print(f"Working on {codename} for the first time!")
                old_data = []
            region = set_region(file)
            if 'V' in version:
                all_versions = [i for i in old_data if i['branch'] == 'stable']
            else:
                all_versions = [i for i in old_data if i['branch'] == 'weekly']
            check = [
                i for i in all_versions
                if i['versions']['miui'] == version and i['region'] == region
            ]
            if check:
                print(f"{codename}: {version} is rolled back ROM, skipping!")
                continue
            # start working
            print("Starting download " + file)
            downloader = Downloader(url=url)
            if downloader.is_running:
                sleep(1)
            print('File downloaded to %s' % downloader.file_name)
            if codename in ARB_DEVICES:
                subprocess.call(
                    ['python3', 'create_flashable_firmware.py', '-F', file])
                subprocess.call(
                    ['python3', 'create_flashable_firmware.py', '-N', file])
            else:
                subprocess.call(
                    ['python3', 'create_flashable_firmware.py', '-F', file])
            remove(file)
            # upload to OSDN/GitHub
            today = str(date.today().strftime('%d.%m.%Y'))
            for file in glob("fw_*.zip"):
                codename = str(file).split("_")[1]
                version = set_version(file)
                upload_fw(file, version, codename, today, variant)
            for file in glob("fw-non-arb_*.zip"):
                codename = str(file).split("_")[1]
                version = set_version(file)
                upload_non_arb(file, version, codename)
            # log the made files
            stable = [f for f in glob("fw*.zip") if "_V1" in f]
            for file in stable:
                branch = 'stable'
                log_new(file, branch)
            weekly = [f for f in glob("fw*.zip") if "_V1" not in f]
            for file in weekly:
                branch = 'weekly'
                log_new(file, branch)
            for file in glob("*.zip"):
                remove(file)
    git_commit_push()
    update_site()
    post_updates()
Beispiel #10
0
    elif 'MI' in version or 'Global' in device:
        region = 'Global'
    else:
        region = 'China'
    return region


GIT_OAUTH_TOKEN = environ['XFU']
gh = GitHub(token=GIT_OAUTH_TOKEN)

bottoken = environ['bottoken']
telegram_chat = "@XiaomiFirmwareUpdater"
work_dir = getcwd()

Downloader(
    url=
    "https://raw.githubusercontent.com/XiaomiFirmwareUpdater/xiaomi-flashable-firmware-creator.py/py/"
    + "xiaomi_flashable_firmware_creator/create_flashable_firmware.py")

with open('devices/stable_devices.json', 'r') as s:
    stable_devices = json.load(s)
with open('devices/weekly_devices.json', 'r') as w:
    weekly_devices = json.load(w)

arb_devices = [
    'nitrogen', 'nitrogen_global', 'sakura', 'sakura_india_global', 'wayne'
]

open('log', 'w').close()

stable_all = json.loads(
    get("https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/"