Exemple #1
0
def file_handler(message):
    answer_succes = "success"
    answer_failed = "failed"
    file_path = FileManager.download_file(bot, message, FileManager.path_for_excel)
    file_first_symbol = message.document.file_name[0]
    type_of_file = None
    answer = "file: {} - ".format(str(message.document.file_name))
    data = ""

    FileManager.if_file_exists_remove(FileManager.path_for_txt)
    FileManager.if_file_exists_remove(FileManager.path_for_excel)

    if file_first_symbol == "s":
        type_of_file = constants.table_session
        sessions = read_session.read_session(file_path)
        count_sessions = len(sessions)
        if sessions:
            for session in sessions:
                data += session.format_print() + "\n"
            if count_sessions > 0:
                answer += answer_succes
        else:
            answer += answer_failed

    elif file_first_symbol == "q":
        type_of_file = constants.table_session
        qualifications = read_session.read_session(file_path)
        count_qualifications = len(qualifications)
        if qualifications:
            for item in qualifications:
                data += item.format_print() + "\n"
            if count_qualifications > 0:
                answer += answer_succes
        else:
            answer += answer_failed
    else:
        type_of_file = constants.table_lessons
        lessons = read_lessons.read_lessons(file_path)
        if lessons:
            weeks = set()
            for lesson in lessons:
                weeks.add(lesson.week)
                data += lesson.format_print() + "\n"
            if len(weeks) == 2:
                answer += answer_succes
        else:
            answer += answer_failed

    if data:
        tools.write_to_file(FileManager.path_for_txt, data)
        with open(FileManager.path_for_txt, "rb") as file:
            bot.send_document(message.chat.id, file)

    bot.send_message(message.chat.id, answer)

    if type_of_file is None:
        bot.send_message(message.chat.id, "don`t found info")
Exemple #2
0
 def get_current_weapon_count(self, weapon):
     pattern = '\t\t<td>%s</td>.*\n.*<td align="right">(.*)</td>' % weapon
     m = re.search(pattern, self.source, re.MULTILINE)
     if m:
         count_without_commas = re.sub(',', '', m.group(1))
         return count_without_commas
     else:
         print 'Cannot find weapon {%s}' % weapon
         tools.write_to_file('weapon_source.txt', source)
         return 0
Exemple #3
0
def fetch_soundcloud(user, album):
    url = soundcloud_url(user, album)
    output_file_name = "soundcloud_%s_%s.txt" % (user, album)

    driver = get_driver()
    driver.get(url)

    titles = fetch_streamer(driver, soundcloud_target_xpath)

    driver.quit()

    write_to_file(output_file_name, titles)
Exemple #4
0
def fetch_youtube(album):
    url = youtube_url(album)

    driver = get_driver()
    driver.get(url)

    list_name = driver.find_element_by_id('title')
    output_file_name = "youtube_%s_%s.txt" % (list_name.text, album)
    titles = fetch_streamer(driver, youtube_target_xpath, 0)

    driver.quit()

    write_to_file(output_file_name, titles)
    def _gen_arrays(self):
        speed_array = []
        friction_array = []
        angle_array = []
        veter_array = []

        speed = self.mu_speed + self.sigma_speed * np.random.randn(self.count_step)
        angle = self.mu_angle + self.sigma_angle * np.random.randn(self.count_step)
        friction = self.mu_trenie + self.sigma_trenie * np.random.randn(self.count_step)
        veter = self.mu_veter + self.sigma_veter * np.random.randn(self.count_step)

        tools.write_to_file('files/gen_data_speed.txt', speed)
        tools.write_to_file('files/gen_data_angle.txt', angle)
        tools.write_to_file('files/gen_data_fric.txt', friction)
        tools.write_to_file('files/gen_data_veter.txt', veter)

        #graf = grafs.Paintgraf()
        #graf.show_hist(speed, self.mu_speed, self.sigma_speed)

        for (i, item) in enumerate(speed):
            speed_array.append(item)

        for (i, item) in enumerate(friction):
            friction_array.append(item)

        for (i, item) in enumerate(angle):
            angle_array.append(item)

        for (i, item) in enumerate(veter):
            veter_array.append(item)

        self._math_array(speed_array, friction_array, angle_array, veter_array)
Exemple #6
0
class GetInfoFromZhihu:
    from tools import Tools

    tools = Tools()
    driver = tools.init_web_driver()

    driver = tools.login(driver=driver)

    driver = tools.click_more(driver=driver)

    titlelist = driver.find_elements_by_css_selector(
        '#zh-profile-activity-page-list > div')
    # zh-profile-activity-page-list > div:nth-child(1)
    # zh-profile-activity-page-list > div:nth-child(17) > div
    # titlelist = driver.find_elements_by_css_selector('#zh-profile-activity-page-list > div:nth-child(1) > div.zm-profile-section-main.zm-profile-section-activity-main.zm-profile-activity-page-item-main')
    print titlelist
    resultlist = []
    for elem in titlelist:

        print '++++' + elem.get_attribute('outerHTML').encode(
            'utf-8').strip() + "++++++"
        elemHTML = elem.get_attribute('outerHTML').encode('utf-8').strip()

        # zh-profile-activity-page-list > div:nth-child(5)
        actionType = tools.found_action_type(elemHTML=elemHTML)

        context = tools.get_context(elem)
        result = [actionType, context]
        resultlist.append(result)

    tools.write_to_file(resultlist)
    # print result + '\n\n\n\n\n\n\n'
    # source_code = driver.page_source
    driver.close()
Exemple #7
0
import logging

from train import run_sentence_sampler
from corpus import read_corpus, Vocabulary
from prob import Uniform
from model import PYPLM

from time import time
from time import strftime

from tools import write_to_file
from parameters import args

now = strftime("%c")
log_dir = "logs/"
write_to_file(filename=log_dir + '/args', data=args)

logging.basicConfig(
    level=logging.DEBUG,
    format=
    '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
    datefmt='%a, %d %b %Y %H:%M:%S',
    filename='./logs/post.log',
    filemode='w',
)

console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
Exemple #8
0
def main():
    tools.print_header()

    parser = argparse.ArgumentParser(description="Build system and library for the RHINO platform and derivatives.")
    parser.add_argument("-e", "--extension-dir", action="append", default=[os.getcwd()])
    parser.add_argument("-p", "--platform", default="rhino")
    parser.add_argument("applications", nargs="+")
    args = parser.parse_args()
    search_dirs = list(map(os.path.abspath, reversed(args.extension_dir)))
    platform = args.platform
    apps = args.applications

    platform_module = tools.try_import(search_dirs, os.path.join("platform", platform), "platform")
    builder_module = tools.try_import(search_dirs, "tools", platform_module.TARGET_VENDOR)

    library_hdl = tools.find_hdl_source_files(os.path.join(search_dir, "library", "hdl") for search_dir in search_dirs)

    # Build each application
    for build_name in apps:
        print(" Building '%s'..." % build_name)

        # Prepare environment
        root_dir, application_dir = tools.find_dir(search_dirs, os.path.join("application", build_name))
        if application_dir is None:
            raise IOError("Could not find application " + build_name)
        build_dir = os.path.join(application_dir, "build")
        output_dir = os.path.join(application_dir, "output")
        tools.mkdir_noerror(build_dir)
        tools.mkdir_noerror(output_dir)
        sys.path.insert(0, root_dir)

        # Build application and generate sources
        application_module = imp.load_source(build_name, os.path.join(application_dir, "top.py"))
        app = platform_module.BaseApp(application_module.COMPONENTS)
        generated_hdl_src, namespace, sig_constraints, platform_commands, symtab_src = app.get_source()

        # Write sources to filesystem
        generated_hdl_file = os.path.join(build_dir, build_name + ".v")
        tools.write_to_file(generated_hdl_file, generated_hdl_src)
        tools.write_to_file(os.path.join(build_dir, build_name + ".symtab"), symtab_src)

        # Build list of HDL sources
        application_hdl = [{"type": "verilog", "path": os.path.join(application_dir, "build", generated_hdl_file)}]
        application_hdl += tools.find_hdl_source_files([os.path.join(application_dir, "hdl")])
        application_hdl += library_hdl

        # Synthesize project
        orig_dir = os.getcwd()
        os.chdir(os.path.join(application_dir, "build"))
        bitstream = builder_module.build(
            platform_module.TARGET_DEVICE, application_hdl, namespace, sig_constraints, platform_commands, build_name
        )
        os.chdir(orig_dir)

        # Create BOF file
        r = subprocess.call(
            [
                "mkbof",
                "-t",
                str(platform_module.MKBOF_HWRTYP),
                "-s",
                os.path.join(build_dir, build_name + ".symtab"),
                "-o",
                os.path.join(output_dir, build_name + ".bof"),
                os.path.join(build_dir, build_name + ".bin"),
            ]
        )
        if r != 0:
            raise OSError("Subprocess failed")

            # Clean up environment
        sys.path.remove(root_dir)

        print(" Completed build of '%s'" % build_name)
Exemple #9
0
#!/usr/bin/python3

__author__ = "Mateusz Kowalski"
__email__ = "*****@*****.**"
__status__ = "Development"

import tools

tools.read_from_file('/etc/hosts')

tools.read_from_file('/afs/cern.ch/user/m/mlisowsk/public/.forward')
tools.write_to_file(
    '/afs/cern.ch/user/m/mlisowsk/public/htcondor_playground/launcher4.txt')

tools.run_application(app="/bin/env")

tools.do_nothing(time=60)
tools.do_heavy_computation(time=60)

tools.do_nothing(time=60 * 5)
tools.do_heavy_computation(time=60 * 5)

tools.do_nothing(time=60 * 60)
tools.do_heavy_computation(time=60 * 60)
def PIPELINE(estimator):
    print(get_accuracy(estimator))
    write_to_file(estimator)
Exemple #11
0
    input_file = sys.argv[1]
    if os.path.isfile(input_file) == True:
        print("Checking if updated")
        book = open(input_file, "r", encoding = 'utf-8')
        old_book = tools.Knigu(book)
        book.close()
        if old_book.is_updated(data.URL, old_book.soup):
            print("File is up to date")
            sys.exit(1)
        else:
            print("File is NOT up to date")
            print("Do you want to update? (y/n): ")
            user_input = input()
            if user_input == "y":
                print("Book being updated...")
                tools.write_to_file(data.URL, old_book.soup, input_file)
                print("Updated!")
                sys.exit(1)
            print("Good bye")
            sys.exit(1)
    else:
        print("Create new book? (y/n): ")
        user_input = input()
        if user_input == "y":
            new_book = tools.Knigu()
            tools.write_to_file(data.URL, new_book.soup, input_file)
            print("Book created and up to date.")
            sys.exit(1)
        print("Good bye.")
        sys.exit(1)
Exemple #12
0
def build(device, sources, namespace, sig_constraints, platform_commands, build_name):
    # Generate UCF
    tools.write_to_file(build_name + ".ucf", _build_ucf(namespace, sig_constraints, platform_commands))

    # Generate project file
    prj_contents = ""
    for s in sources:
        prj_contents += s["type"] + " work " + s["path"] + "\n"
    tools.write_to_file(build_name + ".prj", prj_contents)

    # Generate XST script
    xst_contents = """run
-ifn %s.prj
-top top
-ifmt MIXED
-opt_mode SPEED
-reduce_control_sets auto
-ofn %s.ngc
-p %s""" % (
        build_name,
        build_name,
        device,
    )
    tools.write_to_file(build_name + ".xst", xst_contents)

    # Determine Xilinx tool paths
    def isValidVersion(v):
        try:
            Decimal(v)
            return os.path.isdir(os.path.join(XILINX_INSTALL_PATH, v))
        except:
            return False

    vers = [ver for ver in os.listdir(XILINX_INSTALL_PATH) if isValidVersion(ver)]
    tools_version = str(XILINX_VERSION) in vers and str(XILINX_VERSION) or max(vers)
    xilinx_settings_file = "%s/%s/ISE_DS/settings%d.sh" % (XILINX_INSTALL_PATH, tools_version, XILINX_TOOLS_TYPE)

    # Generate Build script
    build_script_contents = """# Build Script for %s
# Autogenerated by rhino-tools at %s

set -e

source %s
# XST
xst -ifn %s.xst
# NGD
ngdbuild -uc %s.ucf %s.ngc
# Mapping
map -ol high -w %s.ngd
# Place and Route
par -ol high -w %s.ncd %s-routed.ncd
# Generate FPGA configuration
bitgen -g Binary:Yes -w %s-routed.ncd %s.bit
""" % (
        build_name,
        datetime.datetime.now(),
        xilinx_settings_file,
        build_name,
        build_name,
        build_name,
        build_name,
        build_name,
        build_name,
        build_name,
        build_name,
    )
    build_script_file = "build_" + build_name + ".sh"
    tools.write_to_file(build_script_file, build_script_contents)

    r = subprocess.call(["bash", build_script_file])
    if r != 0:
        raise OSError("Subprocess failed")