Exemple #1
0
def download():
    """ Download the latest version of spammers.txt """
    utils.checkout()
    return send_file(
        "git_dir/spammers.txt",
        as_attachment=True,
        attachment_filename="spammers.txt")
Exemple #2
0
def build_translation(apps, _pull=False):
    """ build frappe app's translation """
    from utils import config

    config_apps = config.get("apps")
    update_bench = config.get("update_bench")
    release_bench = config.get("release_bench")
    release_bench_site = config.get("release_bench_site")
    update_bench_site = config.get("update_bench_site")
    commit_msg = config.get(
        "translation_commit_msg") or "[docs] Updated translation"
    base_branches = config.get("base_branch_mapper") or {}

    # import source messages
    exec_cmd(
        update_bench,
        ['bench --site {0} import-source-messages'.format(update_bench_site)])

    # translate unstranslated messages
    exec_cmd(update_bench, [
        'bench --site {0} translate-untranslated-all'.format(update_bench_site)
    ])

    # write csv
    exec_cmd(update_bench, [
        'bench --site {0} execute "translator.data.write_csv_for_all_languages"'
        .format(update_bench_site)
    ])

    # download the translation csv to frappe/erpnext app
    exec_cmd(release_bench, ['bench download-translations'])
    branch = "translations-{0}".format(now_date(format='%Y.%m.%d'))
    try:
        for app in config_apps:
            path = os.path.join(release_bench, 'apps', app)
            if app not in apps:
                exec_cmd(path, ['git stash'])

            if not path:
                print "app is not installed"
                continue

            base_branch = base_branches.get(app, "develop")
            if _pull:
                pull(path, "upstream", base_branch)
            checkout(path, branch, create_new=True)

            args = [
                '{branch}:{branch}'.format(branch=branch),
            ]
            push(app, path, branch, commit_msg)
            pull_request(app, commit_msg, branch, base=base_branch)
            checkout(path,
                     base_branch,
                     delete_branch_after_checkout=True,
                     delete_branch=branch)
    except Exception as e:
        print e
Exemple #3
0
def build_docs(apps, _pull=False):
    """ build frappe app's documentation """
    from utils import config

    release_bench = config.get("release_bench")
    release_bench_site = config.get("release_bench_site")
    commit_msg = config.get("docs_commit_msg")
    target_app_mapper = config.get("docs_target_apps")
    base_branches = config.get("base_branch_mapper") or {}

    branch = "docs-{0}".format(now_date(format='%Y.%m.%d'))
    for app in apps:
        try:
            apps_path = os.path.join(release_bench, 'apps', app)
            if not apps_path:
                print "app is not installed"

            target = target_app_mapper.get(app, {})
            target_app = target.get("app", None)
            owner = target.get("owner", None)
            if not target_app or not owner:
                print "target app mapping not available"

            target_app_path = os.path.join(release_bench, 'apps', target_app)
            if not target_app_path:
                print "app is not installed"

            if _pull:
                pull(apps_path, "upstream", base_branches.get(app, "develop"))
                pull(target_app_path, "upstream",
                     base_branches.get(target_app, "master"))

            checkout(target_app_path, branch, create_new=True)

            # build docs
            exec_cmd(release_bench, \
             ['bench --site {0} build-docs --target {1} {2}'.format(release_bench_site, target_app, app)])

            push(app, target_app_path, branch, commit_msg, commit=True)
            pull_request(target_app,
                         commit_msg,
                         branch,
                         base=base_branches.get(target_app, "master"),
                         owner=owner)
            checkout(target_app_path,
                     base_branches.get(target_app, "master"),
                     delete_branch_after_checkout=False,
                     delete_branch=branch)
        except Exception as e:
            print e
Exemple #4
0
 def start(self):
     if (config['search_dir']
             == []) or (not os.path.exists(utils.name_index_path)):
         QtWidgets.QMessageBox.information(self, '提示', '索引都没有建搜你🐎 搜')
         return
     self.resultTable.setRowCount(0)  # 清空表格
     nc = self.resultCount.value()
     results = utils.checkout(self.input_path[0], self.exists_index, nc)
     results = [i for i in results]
     for i in results:
         row = self.resultTable.rowCount()
         self.resultTable.insertRow(row)
         item = QtWidgets.QTableWidgetItem(i)
         self.resultTable.setItem(row, 0, item)
Exemple #5
0
 def start_search(self):
     if not hasattr(self, 'input_path'):
         self.openfile()
     if (config['search_dir'] == []) or (not os.path.exists(utils.name_index_path)):
         QtWidgets.QMessageBox.information(self, '提示', '索引都没有建搜你🐎 搜')
         return
     self.resultTable.setRowCount(0)                                                                 # 清空表格
     nc = self.resultCount.value()
     results = utils.checkout(self.input_path[0], self.exists_index, nc)
     for i in results:
         row = self.resultTable.rowCount()
         self.resultTable.insertRow(row)
         item_sim = QtWidgets.QTableWidgetItem(f'{i[0]:.2f} %')
         item_sim.setTextAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
         item_path = QtWidgets.QTableWidgetItem(i[1])
         item_path.setToolTip(i[1])
         self.resultTable.setItem(row,0,item_path)
         self.resultTable.setItem(row,1,item_sim)
Exemple #6
0
def download():
    """ Download the latest version of spammers.txt """
    utils.checkout()
    return send_file("git_dir/spammers.txt",
                     as_attachment=True,
                     attachment_filename="spammers.txt")
def main():
    global list_of_urls, found_category
    successful_post = 0
    driver = webdriver.Firefox()

    with requests.Session() as s:

        driver.get('https://www.supremenewyork.com/shop/all')

        print(input('Hit enter to start task:'))

        script_start = time.time()

        header = {
            'Host': 'www.supremenewyork.com',
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0',
            'Accept':
            'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'en-US,en;q=0.5'
        }

        for cookie in driver.get_cookies():
            c = {cookie['name']: cookie['value']}
        s.cookies.update(c)

        while True:
            time.sleep(round(random.uniform(0.2, 1.0), 2))
            for category in categories:
                html = s.get(
                    'https://supremenewyork.com/shop/all/{}'.format(category),
                    headers=header)
                html_doc = BeautifulSoup(html.content, 'html.parser')
                print(
                    colored(
                        '********  Searching through "{}"  ********'.format(
                            category), 'cyan'))
                list_of_urls = product_link(html_doc, keywords)
                if list_of_urls:
                    found_category = category
                    break
            else:
                print(
                    colored(
                        "Couldn't find the product in any of the categories provided.",
                        'red'))
                print(colored('Reloading...', 'green'))
            if list_of_urls:
                break

        for url in list_of_urls:
            header = {
                'Host':
                'www.supremenewyork.com',
                'User-Agent':
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0',
                'Accept':
                'text/html,application/xhtml+xml,application/xml',
                'Accept-Encoding':
                'gzip, deflate',
                'Accept-Language':
                'en-US,en;q=0.5',
                'Referer':
                url,
                'X-XHR-Referer':
                'http://supremenewyork.com/shop/all/{}'.format(found_category)
            }
            page = s.get(url, headers=header)
            product_page = BeautifulSoup(page.content, 'html.parser')
            post_params = get_params(product_page_html=product_page,
                                     wanted_sizes=sizes)
            if post_params:
                post_url = product_page.find(class_='add')
                header = {
                    'Host':
                    'www.supremenewyork.com',
                    'User-Agent':
                    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0',
                    'Accept':
                    '*/*;q=0.5, text/javascript, application/javascript, application/ecmascript, '
                    'application/x-ecmascript',
                    'Accept-Encoding':
                    'gzip, deflate',
                    'Accept-Language':
                    'en-US,en;q=0.5',
                    'Content-Type':
                    'application/x-www-form-urlencoded; charset=UTF-8',
                    'X-Requested-With':
                    'XMLHttpRequest',
                    'Referer':
                    url
                }
                s.post('https://www.supremenewyork.com{}'.format(
                    post_url['action']),
                       data=post_params,
                       headers=header)
                successful_post += 1
            else:
                print(colored('Item is sold out!', 'red'))
        if successful_post > 0:
            for cookie in s.cookies:
                driver.add_cookie({
                    'name': cookie.name,
                    'value': cookie.value,
                    'path': '/',
                })
            driver.get('https://www.supremenewyork.com/checkout')
            print(colored('********  On checkout page!  ********', 'cyan'))
            checkout_page_time = time.time()
            print(
                colored(
                    'Time it took for script to reach checkout: {} seconds'.
                    format(round(checkout_page_time - script_start,
                                 2)), 'yellow'))

            checkout(driver, checkout_values1, script_start, delay)
        else:
            print('No items were added to the cart.')