Ejemplo n.º 1
0
 def follow(self, event):
     t = buffer.get_focused_tweet()
     u = buffer.user(t)
     tw = ask.ask(message="Follow who?",
                  default_value=u)  #not works correctly
     print(tw)
     twitter.Follow(tw)
Ejemplo n.º 2
0
 def _set_dest_node_id(self):
     text = 'What is the receiving node ID?'
     candidate = ask(text)
     if self.trib.is_exist_master_node_id(candidate):
         self.dest_node_id = candidate
     else:
         print(msg_unknown_or_master)
Ejemplo n.º 3
0
 def _nodes(self, default):
     host_list = ask(
         text='Please type host list(comma segmented)? default:',
         default=default)
     self._print('Ok. %s' % host_list)
     host_list = [x.strip() for x in host_list.split(',')]
     return host_list
Ejemplo n.º 4
0
def chooseFile():
    filelist = [fn for fn in os.listdir(SHOP_DIRECTORY) if fn[-3:] in ["txt", "csv"]]
    for i, filename in enumerate(filelist, 1):
        print(i, filename)
    f = ask("Which file do you want to open ?", range(1, len(filelist)+1))
    if not f:   # this doesn't work for the moment, can't figure out how to make it accept a None value
        filename = getLatestFile("csv")
    filename = filelist[int(f)-1]
    return SHOP_DIRECTORY + filename
Ejemplo n.º 5
0
def main():
    shopfile = chooseFile()
    shop_items = getShopItems(shopfile)
    displayShop(shop_items)
    line_start = ask("Which line do you want to start at ?", range(len(shop_items)))
    shop_items = askWhose(shop_items, int(line_start))
    writeShop2File(shop_items, verbose=True)
    displayShop(shop_items)
    calculateMoneyOwed(shop_items)
    return
Ejemplo n.º 6
0
    def _installer(self):
        path_of_cli = config.get_path_of_cli(None)
        release_path = path_of_cli['release_path']
        installer_list = os.listdir(release_path)
        installer_list = list(
            filter(lambda x: x != '.gitignore', installer_list))
        installer_list.sort(reverse=True)
        for i, v in enumerate(installer_list):
            installer_list[i] = '\t({}) {}'.format(i, v)
        '''
        Select installer

        [ INSTALLER LIST ]
            (1) tsr2-installer.bin.flashbase_v1.1.12.centos
            (2) tsr2-installer.bin.flashbase_v1.1.11.centos
            (3) tsr2-installer.bin.flashbase_v1.1.10.centos

        Please enter the number or the path of the installer you want to use
        '''

        msg = [
            'Select installer',
            '[ INSTALLER LIST ]',
            '\n'.join(installer_list),
            '\n',
            'Please enter the number or the path of the installer you want to use',
        ]
        '\n'.join(msg)
        t = '[ INSTALLER LIST ]\n{}\n'.format('\n'.join(installer_list))
        name = ask(
            text=
            'Please type installer. if you want another, type absolute path of installer.\n\n{}'
            .format(t), )
        while True:
            if name in installer_list:
                break
            flag = os.path.exists(name)
            if flag:
                break
            name = ask(text='File not existed. Please confirm and type again')
        self._print('Ok, {}'.format(name))
        return name
  def post(self):
    parser = reqparse.RequestParser()
    parser.add_argument('article_slug', type=str)
    parser.add_argument('article_publisher', type=str)
    parser.add_argument('tokens', type=dict)
    parser.add_argument('size', type=inputs.natural)
    data = parser.parse_args()

    result = ask.ask(data.article_slug, data.article_publisher, data.tokens, data.size)

    return result
Ejemplo n.º 8
0
def base_directory(default='~/tsr2'):
    logger.debug('ask base directory')
    result = ask(message.get('ask_base_directory'), default=default)
    if not result.startswith(('~', '/')):
        logger.error(message.get('error_invalid_path').format(value=result))
        return base_directory()
    logger.info('OK, {}'.format(result))
    cli_config = config.get_cli_config()
    cli_config['base_directory'] = result
    config.save_cli_config(cli_config)
    return result
Ejemplo n.º 9
0
def question_page():
    text = ''
    if request.method == 'POST':
        data = request.data
        question = json.loads(data)['question']
        answer = ask.ask(question, ['answer'],
                         components)[0][5:].replace('_', ' ')
        print('Answer : {}'.format(answer))
        print('_____________________________')
        text = {'question': question, 'answer': answer}
        return jsonify(text)
Ejemplo n.º 10
0
def base_directory(default='~/tsr2'):
    logger.debug('ask base directory')
    result = ask('Type base directory of flashbase', default=default)
    if not result.startswith(('~', '/')):
        logger.error("Invalid path: '{}', try again".format(result))
        return base_directory()
    logger.info('OK, {}'.format(result))
    cli_config = config.get_cli_config()
    cli_config['base_directory'] = result
    config.save_cli_config(cli_config)
    return result
Ejemplo n.º 11
0
def prefix_of_rd(save, default=None):
    logger.debug('ask redis data path')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['prefix_of_rd']
    q = 'Type prefix of {}'
    result = ask(q.format('redis_data'), default=default)
    if save:
        deploy_history['prefix_of_rd'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 12
0
def prefix_of_fdbp(save, default=None):
    logger.debug('ask flash db path')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['prefix_of_fdbp']
    q = 'Type prefix of {}'
    result = ask(q.format('flash_db_path'), default=default)
    if save:
        deploy_history['prefix_of_fdbp'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 13
0
 def get(self):
     """Question に答えます."""
     from ask import ask
     author = self.get_argument('author')
     question = self.get_argument('question')
     answers = {'answers': ask(author, get_entity(question))}
     self.finish(
         dumps(answers,
               ensure_ascii=False,
               indent=4,
               sort_keys=True,
               separators=(',', ': ')))
Ejemplo n.º 14
0
def askWhose(shop_items, start_line=1):
    """
    Since I can't read and write a function at the same time,
    this function will take the list of items, write in a 2nd file,
    delete 1st file and rename 2nd file to 1st filename.
    (for the moment i'm just making it overwrite because annoying
    otherwise)

    Returns a modified shop_items list.
    """
    modified_shopitems = list()
    end = None
    for i, item in enumerate(shop_items):
        if i < start_line:
            modified_shopitems.append(item)
            continue

        who = ask("Who bought - {} - {:<10}".format(item.name, "?"), None, "Enter a flatmate name or a value between 0 and 14.")
        # the formatting thing isn't working

        if not who:
            end = i
            break

        # turn string into one of the groups
        if who.lower() in ["everyone", "ev", "all"]:
            who = "".join(flatmate_initials)
        # else:
            # who = filter(None, re.findall(r"\w*", who)) ??

        # try splitting who by comma, and spaces
        # if no difference, either it's the initials joint together
        # of it's just one name
        # check it against names and diminutives
        # otherwise divide it by characters

        who = "".join(whoIs(person)[0] for person in who)
        who = who.upper()

        whose = ""
        for j, person in enumerate(flatmate_initials):
            if person in who:
                whose += flatmate_initials[j]
            else: whose += " "

        modified_shopitems.append(ShopItem(item.name, item.price, whose))
    
    if end:
        for i, item in enumerate(shop_items):
            if i > end:
                modified_shopitems.append(item)

    return modified_shopitems   # problem here, too easy to lose items
Ejemplo n.º 15
0
def prefix_of_db_path(save, default=None):
    logger.debug('ask_prefix_of_db_path')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['prefix_of_db_path']
    result = ask(message.get('ask_db_path'), default=default)
    result = result.strip()
    if save:
        deploy_history['prefix_of_db_path'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 16
0
def hosts(save, default=None):
    logger.debug('ask host')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['hosts']
    msg = message.get('ask_hosts')
    result = ask(msg, default=', '.join(default))
    result = list(map(lambda x: x.strip(), result.split(',')))
    if save:
        deploy_history['hosts'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 17
0
def hosts(save, default=None):
    logger.debug('ask host')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['hosts']
    q = 'Please type host list separated by comma(,)'
    result = ask(q, default=', '.join(default))
    result = map(lambda x: x.strip(), result.split(','))
    if save:
        deploy_history['hosts'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 18
0
	def ViewUser(self, event):
		inreply=ask.ask(message="View who's user details?",default_value=self.get_user())
		status=twitter.api.get_user(inreply)

		if status.location==None:
			status.location="None"
		if status.description==None:
			status.description="None"
		if status.url==None:
			status.url="None"

		twind=details.DetailsGui("Screen name: "+status.screen_name+"\nName: "+status.name+"\nLocation: "+status.location+"\nUser ID: "+status.id_str+"\nFriends: "+str(status.friends_count)+"\nFollowers: "+str(status.followers_count)+"\nTweets: "+str(status.statuses_count)+"\nFavorites: "+str(status.favourites_count)+"\nIn "+str(status.listed_count)+" lists\nProtected: "+str(status.protected)+"\nVerified: "+str(status.verified)+"\nDescription: "+status.description+"\nNotifications enabled: "+str(status.notifications)+"\nLanguage: "+status.lang+"\nURL: "+status.url+"\nCreation date: "+str(status.created_at)+"\nTime zone: "+status.time_zone,inreply)
		twind.Show()
Ejemplo n.º 19
0
def nodes(save, default=None):
    logger.debug('ask hosts')
    cli_config = config.get_cli_config()
    if not default:
        default = ['127.0.0.1']
        try:
            d = cli_config['default_nodes']
            if d:
                default = d
        except KeyError:
            pass
    result = ask(text='Please type host list separated by comma(,)',
                 default=', '.join(default))
    result = map(lambda x: x.strip(), result.split(','))
    if save:
        cli_config['default_nodes'] = result
        config.save_cli_config(cli_config)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 20
0
    def post(self):
        """Action on google の web フック用レスポンス"""
        from ask import ask
        import json
        data = json.loads(self.request.body)
        LOGGER.info('input: {data}'.format(data=data))

        author = data.get('author', '夏目漱石')
        question = data.get('question')
        answers = ask(author, get_entity(question))

        if answers:
            adjective = answers.get('adjective', None)
            nouns = answers.get('nouns')

            if adjective:
                speech = '。'.join([
                    'それは {adjective} 質問ですね'.format(adjective=adjective[0]),
                    'きっと, {0} や {1} あるいは {2} のことです'.format(*nouns)
                ])
            else:
                speech = 'それはきっと, {0} や {1} あるいは {2} のことです'.format(*nouns)
        else:
            speech = '。'.join([
                '{q} についてですか'.format(q=question), '難しいことを聞きますね', '私にはわからないです'
            ])

        displayText = speech
        respose = {
            'speech': speech,
            'displayText': displayText,
            'data': answers,
            'contextOut': [answers],
            'source': 'how-about-natume'
        }
        self.finish(
            dumps(respose,
                  ensure_ascii=False,
                  indent=4,
                  sort_keys=True,
                  separators=(',', ': ')))
Ejemplo n.º 21
0
def asker(ind):
    global data, results, etalon, threads
    count = 0
    for i in data:
        if break_after > 0 and break_after == count:
            break
        if count % threads == ind:
            t = time.time()
            question = i['question']
            try:
                tmp = ask.ask(question, ['result'], components)
            except:
                print(question)
                continue
            with lock:
                etalon.append(i['result'])
                results.append(tmp)

            if ind == 0:
                print(count)
            res_t = time.time() - t
        count += 1
Ejemplo n.º 22
0
   def _set_src_node_ids(self):
       text = '''Please enter all the source node IDs.
 Type 'all' to use all the nodes as source nodes for the hash slots.
 Type 'done' once you entered all the source nodes IDs.'''
       while True:
           print('src node ids:', self.src_node_ids)
           candidate = ask(text)
           if candidate == 'all':
               self.src_all = True
               tmp = filter(lambda x: self.dest_node_id != x.info['name'],
                            self.trib.master_nodes)
               self.src_node_ids = map(lambda x: x.info['name'], tmp)
               return
           elif candidate == 'done':
               return
           if self.dest_node_id == candidate or candidate in self.src_node_ids:
               print(msg_unknown_or_master)
               continue
           if self.trib.is_exist_master_node_id(candidate):
               self.src_node_ids.append(candidate)
           else:
               print(msg_unknown_or_master)
Ejemplo n.º 23
0
    s = s + "Total amount to pay %.00f" % TotalAmountDiscount + "\n\n\n"
    s = s + "***************************************************************************\n"
    s = s + "                Thank You for Purchase\n"
    s = s + '============================================================================\n'
    readfile.writefile("bill/" + name + " " + str(rand) + ".txt", s)
    return str(s)


ans = True
aa = True
while ans == True:  # to continue prodram untill the user wants it
    from datetime import datetime
    now = datetime.now()
    date = now.strftime("%c")
    print(readfile.fileread())
    a = ask()

    totalAmount, TotalAmountDiscount, disc = calculation.calculation(a)
    print(bill(totalAmount, TotalAmountDiscount, disc, a, date))
    Ask = input(
        "Do you want to continue./n 'y' to continue and 'n' to exit program ")
    while aa == True:  # To check the input of user
        try:
            if Ask == 'y' or Ask == 'yes' or Ask == 'Y' or Ask == 'Yes' or Ask == 'YES':
                ans = True
            elif Ask == 'n' or Ask == 'no' or Ask == 'No' or Ask == 'NO' or Ask == 'N':
                ans = False
            aa = False
        except:
            print("Invalid input")
Ejemplo n.º 24
0
def main(name, articles):
    names = {
        'ac': 'amateur-cities',
        'oo': 'online-open',
        'os': 'open-set',
        'osr': 'open-set-reader'
    }

    publisher = names[name]

    # ----------------------
    # 1. scraping
    if (sys.argv[2] == 'sc'):
        #-- get sitemap
        sitemap = {
            'ac': 'https://amateurcities.com/post-sitemap.xml',
            'oo': 'https://onlineopen.org/sitemap.xml',
            'os': 'http://hub.openset.nl/backend/wp-json',
            'osr':
            'http://openset.nl/reader/pocket/api/get.php?type=root&id=root'
        }

        #-- open-set apis
        apis = {
            'sections': [
                {
                    'type': 'project',
                    'url':
                    'http://hub.openset.nl/backend/wp-json/wp/v2/project',
                    'data': {}
                },
                {
                    'type': 'expertinput',
                    'url':
                    'http://hub.openset.nl/backend/wp-json/swp_api/search',
                    'data': {}
                },
            ],
            'categories': {
                'type': 'categories',
                'url':
                'http://hub.openset.nl/backend/wp-json/wp/v2/categories',
                'data': {}
            }
        }

        t_url = sitemap[name]
        r = requests.get(t_url)
        data = r.text

        #-- make dict with { <lastmod>: <url> }
        sm = BeautifulSoup(data, "lxml")

        sm_index = []
        for item in sm.find_all('url'):
            url = item.find('loc')
            ts = item.find('lastmod')
            if ts is not None:
                entry = (ts.text, url.text)
                sm_index.append(entry)

        # url = []
        # mod = []

        # for online-open (and anyone else), let's force add a UTC timezone
        # at the end of the date-timestamp, so we can match the date-timestamp
        # coming from the postgresql db, which automatically at a UTC tz as well
        # (this means a `+00:00` after `2019-07-04T22:00:00`, therefore
        # all date-timestamp are now in the full isodate format of
        # `2019-07-04T22:00:00+00:00`
        # mod = [ciso8601.parse_datetime(mod).astimezone(tz=timezone.utc).isoformat() for mod in mod]

        mod_t = []
        c = Counter()
        for item in sm_index:
            item_y = ciso8601.parse_datetime(
                item[0]).astimezone(tz=timezone.utc).isoformat()
            if item_y in mod_t:
                c.update({item_y: 1})
                print(c)

                item = ciso8601.parse_datetime(
                    item[0]).astimezone(tz=timezone.utc)
                # <https://stackoverflow.com/a/100345>
                # use c = Counter to *monotonically* increase the timestamp of <modlast> items with only the date, by 1 sec each time
                tt = item + timedelta(0, c[item_y])
                t = tt.isoformat()
                mod_t.append(t)
            else:
                t = ciso8601.parse_datetime(
                    item[0]).astimezone(tz=timezone.utc).isoformat()
                mod_t.append(t)

        url = [x[1] for x in sm_index]
        last_mod = dict(zip(mod_t, url))
        print('LASTMOD', last_mod)

        datb_mod = get_from_db.get_mod(publisher)

        #--- compare mod from db w/ mod from fresh scraping lookup
        # https://blog.softhints.com/python-compare-dictionary-keys-values/

        def scrape_lookup(datb_mod, last_mod, publisher):
            # check if db has records of this publisher
            index_diff = {}
            if bool(datb_mod) is True:
                db_mod = set(datb_mod.keys())
                sc_mod = set(last_mod.keys())
                mod_diff = sc_mod.difference(db_mod)

                # https://stackoverflow.com/a/17665928
                def ts_diff(diff, main_list):
                    y = [k for k in main_list if k not in diff]
                    return {k: main_list[k] for k in main_list if k not in y}

                # diff b/t fresh scraped articles and db
                index_diff['action'] = 'update'
                index_diff['entries'] = ts_diff(mod_diff, last_mod)
                index_diff['count'] = len(index_diff['entries'])

                print('-- index-diff --')
                print(index_diff)

                return index_diff
            else:
                print('db data for %s is still empty' % publisher)
                index_diff['action'] = 'add'
                index_diff['entries'] = last_mod
                index_diff['count'] = len(index_diff['entries'])
                return index_diff

        # this is the index_diff b/t db articles and online www
        mod_list = scrape_lookup(datb_mod, last_mod, publisher)

        def add_to_db(mod_list_count, mod_list_action, article, old_article):
            # check mod_list['action'] type to pick between
            # `scrape_update` & `scrape`
            if mod_list_count >= 0 and mod_list_action == 'update':
                print('update db record')
                save_to_db.scrape_update(article, old_article)
            else:
                print('save to db')
                save_to_db.scrape(article)

        #--- scraping + saving
        def scrape(name, publisher, mod_list, sitemap):
            with requests.Session() as s:

                # ac
                if (name == 'ac'):
                    for mod, url in mod_list['entries'].items():
                        old_article = url
                        article = {}
                        ac.scraper(s, mod, url, publisher, article)
                        articles.append(article)

                        add_to_db(mod_list['count'], mod_list['action'],
                                  article, old_article)

                # oo
                elif (name == 'oo'):
                    for mod, url in mod_list['entries'].items():
                        old_article = url
                        article = {}
                        oo.scraper(s, mod, url, publisher, article)
                        articles.append(article)

                        add_to_db(mod_list['count'], mod_list['action'],
                                  article, old_article)

                # ---
                # not using `add_to_db` function for os and osr
                # just checking if articles are saved in db once
                # after that no more scraping;
                # for os no more articles, for osr some new articles
                # will be manually added to db

                # os
                elif (name == 'os'):
                    # feed `apis[item.data{}]` w/ data
                    def getData(item):
                        item['data'] = requests.get(item['url']).json()

                    # fetch data for sections items and categories
                    for section in apis['sections']:
                        getData(section)

                    getData(apis['categories'])

                    if mod_list['count'] >= 0 and mod_list['action'] == 'add':
                        for item in section['data']:
                            article = {}
                            oss.scraper(section, item, apis, article)
                            articles.append(article)
                            save_to_db.scrape(article)
                    else:
                        print('os: db is full, no new articles to fetch')

                # osr
                elif (name == 'osr'):

                    def get_sitemap(path):
                        slugs = []
                        with open(path) as table:
                            reader = csv.reader(table, delimiter=';')
                            for row in reader:
                                slugs.append(row[1].split('/')[-1])

                        return slugs

                    slug_list = get_sitemap("store/open-set-articles.csv")
                    print(slug_list)

                    if mod_list['count'] >= 0 and mod_list['action'] == 'add':
                        for slug in slug_list:
                            article = {}
                            osr.scraper(s, slug, article)
                            articles.append(article)
                            save_to_db.scrape(article)
                    else:
                        print('osr: db is full, no new articles to fetch')

                else:
                    print('mod_list empty: nothing to scrape')

        #-- do the scraping
        scrape(sys.argv[1], publisher, mod_list, sitemap)

    # ------------------
    # 2. text-processing
    elif (sys.argv[2] == 'tx'):
        articles = get_from_db.get_body(publisher)

        for item in articles:
            try:
                article_metadata = {}
                metadata = text_processing.process_metadata(
                    item, article_metadata, publisher)
                save_to_db.metadata(metadata)
            except Exception as e:
                print('text-processing ERROR:', e)

    # ------------------
    # 3. text-tokenization
    elif (sys.argv[2] == 'tk'):
        articles = get_from_db.get_metadata_for_pub(publisher)

        for item in articles:
            try:
                article_tokens = {}
                article_tk = {}

                text_processing.process_tokens(item, article_tk)

                article_tokens['title'] = item['title']
                article_tokens['author'] = item['author']
                article_tokens['publisher'] = item['publisher']
                article_tokens['word_freq'] = article_tk['word_freq']
                article_tokens['2-word_freq'] = article_tk['2-word_freq']
                article_tokens['3-word_freq'] = article_tk['3-word_freq']
                article_tokens['tokens'] = article_tk
                article_tokens['hash'] = item['hash']

                save_to_db.tokens(article_tokens)

            except Exception as e:
                print('text-processing ERROR:', e)

    # -------------------
    # 4. train model
    # -- do it once as init process
    elif (sys.argv[2] == 'tm'):
        print(publisher, 'tm')
        ask(train=True)
        # ask.ask(train)

    # 5. tags
    # check for empty tags in `metadata` and
    # bring back original tags from `scraper`
    elif (sys.argv[2] == 'tags'):
        articles = get_from_db.get_empty_tags(publisher)

        tags_i = [item['tags'] for item in articles]
        tags_db = [l[0] for l in tags_i]

        tags = set(tags_db)

        for article in articles:
            for k, v in article.items():
                print(v)

        for tag in tags:
            print('- ', tag)
Ejemplo n.º 25
0
 def unfollow(self, id):
     t = buffer.get_focused_tweet()
     u = buffer.user(t)
     tw = ask.ask(message="Unfollow who?", default_value=u)
     twitter.Unfollow(tw)
Ejemplo n.º 26
0
def q3():
     anwser = ask(c.yellow + "Who is Jake's best friend" + c.yellow)
     if anwser.startswith('Rees' or 'Drake' or 'John' or 'Grayson' or 'Christon' or 'Lydia' or 'Connor' or 'Fisher'):
         return True
     return False
Ejemplo n.º 27
0
def installer():
    '''
    Select installer from list of '$FBPATH/releases'
    or input absolute path of file directly
    return installer path
    '''
    logger.debug('ask installer')
    path_of_cli = config.get_path_of_cli(None)
    release_path = path_of_cli['release_path']
    if not os.path.exists(release_path):
        os.mkdir(release_path)
    installer_list = os.listdir(release_path)
    installer_list = list(filter(lambda x: x != '.gitignore', installer_list))
    installer_list.sort(reverse=True)

    # formatting msg
    formatted = []
    for i, name in enumerate(installer_list):
        formatted.append('    ({index}) {name}'.format(index=i + 1, name=name))
    msg = [
        'Select installer',
        '',
        '    [ INSTALLER LIST ]',
        '{}\n'.format('\n'.join(formatted)),
        'Please enter the number or the path of the installer you want to use',
        "you can also add file in list by copy to '$FBPATH/releases/'",
    ]
    if not installer_list:
        msg = [
            'Select installer',
            '',
            '    [ INSTALLER LIST ]',
            '    (empty)\n\n'
            'Please enter the path of the installer you want to use',
            "you can also add file in list by copy to '$FBPATH/releases/'",
        ]

    result = ask('\n'.join(msg))
    while True:
        if installer_list and result.decode('utf-8').isdecimal():
            # case: select in list
            result = int(result) - 1
            if result in range(0, len(installer_list)):
                ret = path_join(release_path, installer_list[result])
                logger.debug('Select insaller in list: {}'.format(ret))
                logger.info('OK, {}'.format(installer_list[result]))
                return os.path.expanduser(ret)
            msg = [
                'Choose a number ',
                'between 1 and {}'.format(len(installer_list)),
                ', please try again'
            ]
            logger.error(''.join(msg))
        elif result.startswith(('~', '/')):
            # case: type path
            if os.path.isfile(os.path.expanduser(result)):
                logger.debug('Select insaller by path: {}'.format(result))
                logger.info('OK, {}'.format(os.path.basename(result)))
                return os.path.expanduser(result)
            msg = [
                "File not existed: '{}'".format(result), ', please try again'
            ]
            logger.error(''.join(msg))
        else:
            msg = [
                "Invalid input: '{}', ".format(result),
                "please try again",
            ]
            logger.error(''.join(msg))
        result = ask('')
Ejemplo n.º 28
0
	def Unblock(self, event):
		twindow=ask.ask(message="Unblock who?",default_value=self.get_user())
		status=twitter.Unblock(twindow)
Ejemplo n.º 29
0
	def Follow(self, event):
		twindow=ask.ask(message="Follow who?",default_value=self.get_user())
		status=twitter.Follow(twindow)
Ejemplo n.º 30
0
	def Timeline(self, event):
		twindow=ask.ask(message="Open which timeline?",default_value=self.get_user())
		twitter.create_user_timeline(twindow)
Ejemplo n.º 31
0
def q3():
    anwser = ask(c.magenta + 'Please use one word to describe the texture of their magical fur:')
    if anwser.startswith('smiles'):
        return True
    return False
Ejemplo n.º 32
0
def master_ports(save, cluster_id, default_count=None):
    logger.debug('ask master ports')
    deploy_history = config.get_deploy_history()
    if not default_count:
        default_count = deploy_history['master_count']
    msg = message.get('ask_master_count')
    m_count = int(askInt(msg, default=str(default_count)))
    if m_count <= 0:
        logger.error(message.get('error_master_count_less_than_1'))
        return master_ports(cluster_id, default_count)
    logger.info('OK, {}'.format(m_count))
    if save:
        deploy_history['master_count'] = m_count
        config.save_deploy_history(deploy_history)

    start_m_ports = START_PORT + cluster_id * MASTER_OFFSET
    end_m_ports = start_m_ports + m_count - 1
    if start_m_ports == end_m_ports:
        default_m_ports = str(start_m_ports)
    else:
        default_m_ports = '{}-{}'.format(start_m_ports, end_m_ports)

    while True:
        result = ask(message.get('ask_ports'), default=default_m_ports)
        result = list(map(lambda x: x.strip(), result.split(',')))
        valid = True
        m_ports = set()
        pattern = re.compile('[0-9]+-[0-9]+')
        for item in result:
            # range number
            matched = pattern.match(item)
            if matched:
                s, e = map(int, item.split('-'))
                if s > e:
                    msg = message.get('error_invalid_range').format(value=item)
                    logger.error(msg)
                    valid = False
                    break
                m_ports.update(range(s, e + 1))
                continue
            # single number
            elif utils.is_number(item):
                m_ports.add(int(item))
                continue
            else:
                msg = message.get('error_invalid_input').format(value=item)
                logger.error(msg)
                valid = False
                break
        if not valid:
            continue
        out_of_range = []
        for port in m_ports:
            if not port_range_safe(port):
                out_of_range.append(port)
        if out_of_range:
            msg = message.get('error_port_range').format(
                minimum=PORT_MININUM,
                maximum=PORT_MAXIMUM,
                value=out_of_range,
            )
            logger.error(msg)
            continue
        if valid and len(m_ports) != m_count:
            msg = message.get('error_port_count_different').format(
                advance=m_count,
                current=len(m_ports),
            )
            logger.error(msg)
            continue
        if valid:
            break
    m_ports = sorted(list(m_ports))
    logger.info('OK, {}'.format(result))
    return m_ports
Ejemplo n.º 33
0
def q2():
    anwser = ask(c.magenta + 'Where are they danceing?')
    if anwser.startswith('rainbows'):
        return True
    return False
Ejemplo n.º 34
0
def q1():
    anwser = ask(c.yellow + 'How old is Jake?' + c.yellow)
    if anwser.startswith('12.5'):
        return True
    return False
Ejemplo n.º 35
0
from picture import pic

if sys.version_info[0] != 3:
    print("This script requires Python 3")
    exit()

while(1):
    count = input("How many pictures do you have?\n")
    try:
        count = int(count)
        break
    except ValueError:
        print("This value is not valid! Try again!")
        time.sleep(2)

a = ask.ask(count)
picArray = []
for i in range(count):
    if len(picArray)>0:
        a.printHeader(i, True, picArray[-1].strTime)
        path = a.askPath()
        sumSecTime = sum(pic.secTime for pic in picArray)
        #print(sumSecTime)
    else:
        a.printHeader(i, False, "")
        path = a.askPath()
        sumSecTime = 0
        
    print()
    strTime = a.askTime(sumSecTime)
    picObject = pic(strTime, path, sumSecTime)
Ejemplo n.º 36
0
    q = " -q"  # quiet flag for git commands

    os.system("clear")
    print("-----------------------------")
    print(" Divio DjangoCMS Initializer")
    print("-----------------------------")
    ask.explain(True)
    i = ask.askBool("Do you want the script to create your Github repo?", default='y')
    if i == 'y':
        try:
            from pyrate.services import github
        except ImportError:
            raise ImportError("Warning: Pyrate could not be found."
                              "Please install it and try again. (pip install pyrate -U)")

        github_user = ask.ask("Please enter your Github username")
        github_pass = ask.askPassword("Please enter your Github password")
        github_org = ask.ask("If you want to create the repo on an organisation's account, "
                           "enter its name now. Otherwise hit enter", default='')
        project_name = ask.ask("Please enter a name for the repo")
        project_private = ask.askBool("Should the repo be private?", default='y')
        if project_private == 'y':
            project_private = True

        elif project_private == 'n':
            project_private = False

        h = github.GithubPyrate(github_user, github_pass)
        if github_org:
            h.create_repo(project_name, org_name=github_org, private=project_private)
            repo_owner = github_org
Ejemplo n.º 37
0
def process(activity):
	# print activity
	# activity_list = activity.split()
	punctuation = set(string.punctuation)
	plainTerms = ["a", "e", "i", "o", "u", "y", "me", "you", "of", "in", "for", "at", "the", "an"]
	locSearchTerms = ["find", "locate", "located", "location", "where", "search for"]
	ISSterms = ["international space station", "the space station", "space station", "iss"]
	googleMapsTerms = ["map", "maps", "google"]
	aboutMeQuestions = ["who are you?", "who are you", "what is your name?", "what is your name", "explain yourself", "tell me about yourself"]
	doneTerms = ["quit", "done", "nevermind", "leave", "leave me alone", "shutdown", "no"]
	doneMatchTerms = ["quit", "done", "leave", "peace", "bye", "goodbye", "shutdown", "shut down", "turn off", "off"]
	gratefulTerms = ["thanks", "thank you", "i appreciate", "please"]
	shutdownTerms = ["shutdown", "shut down", "off", "turn off"]
	welcomeResponses = ["You're very welcome, sir.", "My pleasure.", "Of course."]
	doneTerms = doneTerms + doneMatchTerms + shutdownTerms
	activityClean = stripPunc(activity, punctuation, [])
	activityPosNeg = stripPunc(activity, punctuation, ["+", "-"])
	activity_list = activityClean.split()
	activity_list_pos_neg = activityPosNeg.split()
	# print activity_list_pos_neg


	if activity[:len("mdfind")].lower() == "mdfind":
		# print os.system(activity)
		search_results = str(os.system(activity))
		# print search_results
		# print type(search_results)
		line_count = 0
		# while line_count < 5:
		# 	print search_results[line_count]
		# 	line_count += 1
		return True

	"""The following for loop checks if gratefulTerms[x] in IN the activity string, or if it IS the activity string.  
	Once it finds a match, either it leaves the function, or it leaves the for loop and continues throught the function"""
	for term in gratefulTerms:
		if term in activity:
			x = random.randrange(0,len(welcomeResponses))
			respond(welcomeResponses[x])
			if term == activity:
				return True
			else:
				break


	for term in aboutMeQuestions:
		if activity == term:
			aboutMe.iAmBeeker()
			return True
	if activity[:len('wiki')] == "wiki" or activity[:len('wikipedia')] == "wikipedia":
		# respond(wikipedia.summary(activity[len('wiki'):]))
		searchWiki.getWiki(activity)
		return True
	if activity[:len('summarize')] == "summarize" or activity[:len('summary')] == "summary":
		# respond(wikipedia.summary(activity[len('summarize'):], sentences = 2))
		searchWiki.getWiki(activity)
		return True
	if 'question' in activity:
		respond("What would you like to know?")
		question = raw_input("\n ")
		question = question.lower()

		print '\n'
	
		if question == 'quit()' or 'done' in question or 'nevermind' in question:
			greetings.anyMoreQuestions()
		else:
			ask(question)
			return True
	if 'time' in activity and 'in' not in activity:
		if getTime(activity) == False:
			respond("That didn't make sense")
		return True
	if "weather" in activity or "forecast" in activity:
		# pattern = re.compile("\\b(of|the|in|for|at|weather|check|find|how|how's|is|tell|me|check|out|about)\\W", re.I)
		# string = re.sub(pattern, "", activity)
		# string = string.replace(" ", "")
		if "forecast" in activity:
			weatherCheck.getForecast(activity)
		else:
			# weatherCheck.getWeather(activity)
			checkWeather()
		respond("Finished weather check")
		return True


	
	for term in ISSterms:
		if term in activity.lower():
			# print "Found:", term
			for word in locSearchTerms:
				if word in activity:
					# print "Found:", word
					locateISS()
					return True

	# for term in acivity:
	# 	term = term.lower()
		# if term in locSearchTerms and term in ISSterms:
		# 	locateISS()
		# elif term in locSearchTerms and term in googleMapsTerms:
	for term in googleMapsTerms:
		if term in activity_list_pos_neg:
			try:
				latitude = float(activity_list_pos_neg[1])
				longitude = float(activity_list_pos_neg[2])
				# print latitude, longitude
				googleMaps(latitude, longitude, True)
			except:
				respond("If you're trying to use Google Maps, make sure to use two numbers")
			return True



	grateful = False

	for term in doneTerms:
		if term in activity:
			# print "Found a doneTerms item:",activity
			if 'off' in activity or 'down' in activity or 'shut' in activity:
				for item in shutdownTerms:
					if item == activity:
						greetings.shutdownGoodbye()
						sys.exit(0)
				if 'piss off' in activity or 'f**k off' in activity:
					greetings.madGoodbye()
					sys.exit(0)
		if activity[len(activity)-len(term):] == term or activity[:len(term)] == term:
			# print "Found a doneTerms item at end of string:", activity
			for term in gratefulTerms:
				if term in activity:
					grateful = True
			if grateful == False:
				respond("Very well, sir.")		
			greetings.goodbye()
			sys.exit(0)
		
	return False
Ejemplo n.º 38
0
def q1():
    anwser = ask(c.magenta + 'What color are the unicorns?' + c.magenta)
    if anwser.startswith('pink'):
        return True
    return False
Ejemplo n.º 39
0
def master_ports(save, cluster_id, default_count=None):
    logger.debug('ask master ports')
    deploy_history = config.get_deploy_history()
    if not default_count:
        default_count = deploy_history['master_count']
    q = 'How many masters would you like to create on each host?'
    m_count = int(askInt(q, default=str(default_count)))
    if m_count <= 0:
        logger.warn("The number of master must be greater than 0. try again.")
        return master_ports(cluster_id, default_count)
    logger.info('OK, {}'.format(m_count))
    if save:
        deploy_history['master_count'] = m_count
        config.save_deploy_history(deploy_history)

    start_m_ports = START_PORT + cluster_id * MASTER_OFFSET
    end_m_ports = start_m_ports + m_count - 1
    if start_m_ports == end_m_ports:
        default_m_ports = str(start_m_ports)
    else:
        default_m_ports = '{}-{}'.format(start_m_ports, end_m_ports)

    q = [
        'Please type ports separate with comma(,) ',
        'and use hyphen(-) for range.',
    ]
    while True:
        result = ask(''.join(q), default=default_m_ports)
        result = map(lambda x: x.strip(), result.split(','))
        valid = True
        m_ports = set()
        pattern = re.compile('[0-9]+-[0-9]+')
        for item in result:
            # range number
            matched = pattern.match(item)
            if matched:
                s, e = map(int, item.split('-'))
                if s > e:
                    logger.error('Invalid range: {}'.format(item))
                    valid = False
                    break
                m_ports.update(range(s, e + 1))
                continue
            # single number
            elif item.decode('utf-8').isdecimal():
                m_ports.add(int(item))
                continue
            else:
                logger.error('Invalid input: {}'.format(item))
                valid = False
                break
        if not valid:
            continue
        out_of_range = []
        for port in m_ports:
            if not port_range_safe(port):
                out_of_range.append(port)
        if out_of_range:
            msg = 'Use port between {} and {}: {}'.format(
                PORT_MININUM,
                PORT_MAXIMUM,
                out_of_range,
            )
            logger.error(msg)
            continue
        if valid and len(m_ports) != m_count:
            q2 = [
                "You type count '{}' at first, ".format(m_count),
                "but now count is '{}'. ".format(len(m_ports)), 'try again.'
            ]
            logger.error(''.join(q2))
            continue
        if valid:
            break
    m_ports = sorted(list(m_ports))
    logger.info('OK, {}'.format(result))
    return m_ports
Ejemplo n.º 40
0
def installer():
    '''
    Select installer from list of '$FBPATH/releases'
    or input absolute path of file directly
    return installer path
    '''
    logger.debug('ask installer')
    path_of_cli = config.get_path_of_cli(None)
    release_path = path_of_cli['release_path']
    if not os.path.exists(release_path):
        os.mkdir(release_path)
    installer_list = net.get_installers_from_fb_s3()
    buf = os.listdir(release_path)
    buf = list(filter(lambda x: x != '.gitignore', buf))
    pattern = '.download'
    buf = list(filter(lambda x: pattern not in x, buf))
    for file_name in buf:
        installer_list.append({
            'name': file_name,
            'url': os.path.join(release_path, file_name),
            'type': 'local',
        })

    # formatting msg
    formatted = []
    for i, obj in enumerate(installer_list):
        formatted.append('    ({index}) [{type}] {name}'.format(
            index=i + 1,
            name=obj['name'],
            type=obj['type'].upper(),
        ))
    if not formatted:
        formatted.append('    (empty)')

    stringfied_list = '\n'.join(formatted)
    msg = '\n'.join(message.get('ask_installer')).format(list=stringfied_list)
    result = ask(msg)
    while True:
        result = result.strip()
        if installer_list and utils.is_number(result):
            # case: select in list
            result = int(result) - 1
            if result in range(0, len(installer_list)):
                selected = installer_list[result]
                if selected['type'] == 'download':
                    url = selected['url']
                    file_name = selected['name']
                    installer_path = os.path.join(release_path, file_name)
                    success = net.download_file(url, installer_path)
                    if success:
                        logger.info('OK, {}'.format(file_name))
                        return installer_path
                    msg = message.get('error_download_installer')
                    msg = msg.format(url=url)
                    logger.error(msg)
                if selected['type'] == 'local':
                    ret = selected['url']
                    logger.debug('Select insaller in list: {}'.format(ret))
                    logger.info('OK, {}'.format(selected['name']))
                    return os.path.expanduser(ret)
            msg = message.get('error_select_number')
            msg = msg.format(max_number=len(installer_list))
            logger.error(msg)
        elif result.startswith(('~', '/')):
            # case: type path
            if os.path.isfile(os.path.expanduser(result)):
                logger.debug('Select insaller by path: {}'.format(result))
                logger.info('OK, {}'.format(os.path.basename(result)))
                return os.path.expanduser(result)
            msg = message.get('error_type_installer_path')
            msg = msg.format(file_path=result)
            logger.error(msg)
        elif result.startswith(('http://', 'https://')):
            # case: type url
            url = result
            file_name = url.split('?')[0].split('/')[-1]
            installer_path = os.path.join(release_path, file_name)
            success = net.download_file(url, installer_path)
            if success:
                logger.info('OK, {}'.format(file_name))
                return installer_path
            msg = message.get('error_download_installer')
            msg = msg.format(url=url)
            logger.error(msg)
        else:
            msg = message.get('error_invalid_input')
            msg = msg.format(value=result)
            logger.error(msg)
        result = ask('')
Ejemplo n.º 41
0
def slave_ports(cluster_id, m_count, replicas_count):
    logger.debug('ask slave ports')
    if replicas_count <= 0:
        logger.debug('return empty list')
        return []
    s_count = m_count * replicas_count
    start_s_ports = START_PORT + (cluster_id * MASTER_OFFSET) + SLAVE_OFFSET
    end_s_ports = start_s_ports + s_count - 1
    if start_s_ports == end_s_ports:
        default_s_ports = str(start_s_ports)
    else:
        default_s_ports = '{}-{}'.format(start_s_ports, end_s_ports)
    q = [
        'Please type ports separate with comma(,) ',
        'and use hyphen(-) for range.',
    ]

    while True:
        result = ask(''.join(q), default=default_s_ports)
        result = map(lambda x: x.strip(), result.split(','))
        valid = True
        s_ports = set()
        p = re.compile('[0-9]+-[0-9]+')
        for item in result:
            # range number
            m = p.match(item)
            if m:
                s, e = map(int, item.split('-'))
                if s > e:
                    logger.error('Invalid range: {}'.format(item))
                    valid = False
                    break
                s_ports.update(range(s, e + 1))
                continue
            # single number
            elif item.decode('utf-8').isdecimal():
                s_ports.add(int(item))
                continue
            else:
                logger.error('Invalid input: {}'.format(item))
                valid = False
                break
        out_of_range = []
        for port in s_ports:
            if not port_range_safe(port):
                out_of_range.append(port)
        if out_of_range:
            logger.error('Use port between {} and {}: {}'.format(
                PORT_MININUM, PORT_MAXIMUM, out_of_range))
            continue
        if valid and len(s_ports) != s_count:
            msg = [
                "You type replicas '{}' at first, ".format(replicas),
                "but now count is '{}'. ".format(
                    len(s_ports) / float(m_count)), 'try again.'
            ]
            logger.error(''.join(msg))
            continue
        if valid:
            break
    s_ports = sorted(list(s_ports))
    logger.info('OK, {}'.format(result))
    return s_ports
Ejemplo n.º 42
0
                dungeon[p_y][p_x] = c.blue + '●'
        except IndexError:
            pass
    if c.green + '$' in last_tile_rep:
        clear()
        getch.pause('Fin.')
        return True
    return [dungeon, last_tile_rep]


if __name__ == '__main__':
    clear()
    width = 0
    height = 0
    while width <= 0 or height <= 0 or width * height < 2:
        width = ask('Please input the width of your dungeon', int)
        clear()
        height = ask('Please input the height of your dungeon', int)
        clear()
    dungeon = build_dungeon(width, height)
    last_tile_rep = c.base03 + '$'
    while True:
        dungeon = printing(dungeon, width, height)
        dungeon = moving(dungeon, last_tile_rep, width, height)
        if dungeon == True:
            break
        else:
            last_tile_rep = dungeon[1]
            dungeon = dungeon[0]
    clear()
Ejemplo n.º 43
0
def slave_ports(cluster_id, m_count, replicas_count):
    logger.debug('ask slave ports')
    if replicas_count <= 0:
        logger.debug('return empty list')
        return []
    s_count = m_count * replicas_count
    start_s_ports = START_PORT + (cluster_id * MASTER_OFFSET) + SLAVE_OFFSET
    end_s_ports = start_s_ports + s_count - 1
    if start_s_ports == end_s_ports:
        default_s_ports = str(start_s_ports)
    else:
        default_s_ports = '{}-{}'.format(start_s_ports, end_s_ports)

    while True:
        result = ask(message.get('ask_ports'), default=default_s_ports)
        result = list(map(lambda x: x.strip(), result.split(',')))
        valid = True
        s_ports = set()
        p = re.compile('[0-9]+-[0-9]+')
        for item in result:
            # range number
            m = p.match(item)
            if m:
                s, e = map(int, item.split('-'))
                if s > e:
                    msg = message.get('error_invalid_range').format(value=item)
                    logger.error(msg)
                    valid = False
                    break
                s_ports.update(range(s, e + 1))
                continue
            # single number
            elif utils.is_number(item):
                s_ports.add(int(item))
                continue
            else:
                msg = message.get('error_invalid_input').format(value=item)
                logger.error(msg)
                valid = False
                break
        out_of_range = []
        for port in s_ports:
            if not port_range_safe(port):
                out_of_range.append(port)
        if out_of_range:
            msg = message.get('error_port_range').format(
                minimum=PORT_MININUM,
                maximum=PORT_MAXIMUM,
                value=out_of_range,
            )
            logger.error(msg)
            continue
        if valid and len(s_ports) != s_count:
            real_replicas_count = len(s_ports) / float(m_count)
            msg = message.get('error_port_count_different').format(
                advance=replicas_count,
                current=int(real_replicas_count),
            )
            logger.error(msg)
            continue
        if valid:
            break
    s_ports = sorted(list(s_ports))
    logger.info('OK, {}'.format(result))
    return s_ports
Ejemplo n.º 44
0
#!/usr/bin/env python3
import skilstak.colors as c
from ask import ask
import random
def clear():
  print(c.clear,end='')
clear()

difficulty = ask('Difficulty (5-10)?', int, '>>> ', [5,6,7,8,9,10])
input(difficulty)
difficulty += 1
input(difficulty)











raise
clear()
with open('/home/error404/side-projects/words.txt') as words_file:
  words = words_file.read()
  words_file.close()

word_options = []
Ejemplo n.º 45
0
    ]
    l = [
        f[:-5] for f in os.listdir("AUTOSAVE")
        if (not os.path.isdir(f)) and f[-5:] == ".json" and len(f) == 15
    ]
    l.sort(key=lambda a: int(a[:-5]))
    l = list(reversed(l))
    json_files_alt_2 = list(reversed([f[-4:] for f in l[:10]]))

    #print(json_files_alt_2)

    choice = 'l'
    while choice == 'l':
        choice = ask(
            "Which graph do you want to show : " + str([
                d for d in os.listdir()
                if (os.path.isdir(d) or d[-5:] == ".json") and d != "AUTOSAVE"
            ]) + " --> ", directories + json_files + json_files_alt +
            json_files_alt_2 + ['l'] + main_json_files + main_json_files_alt)
        if choice == 'l':
            print(json_files_alt_2)

    g = Graph()

    if choice in directories:
        os.chdir(choice)

        mp.title("Trajectories")
        for name in os.listdir():
            data = get_data_from_json(name)
            g.add_data_set(data["x"], data["y"])
        g.show()
Ejemplo n.º 46
0
def home(activity):
	if process(activity):
		pass
	else:
		print '\n'
		ask(activity)
Ejemplo n.º 47
0
        p_x += 1
        dungeon[p_y][p_x] = c.blue + '●'
    except IndexError:
      pass
  if c.green + '$' in last_tile_rep:
    clear()
    getch.pause('Fin.')
    return True
  return [dungeon,last_tile_rep]

if __name__ == '__main__':
  clear()
  width = 0
  height = 0
  while width <= 0 or height <= 0 or width * height < 2:
    width = ask('Please input the width of your dungeon',int)
    clear()
    height = ask('Please input the height of your dungeon',int)
    clear()
  dungeon = build_dungeon(width, height)
  last_tile_rep = c.base03 + '$'
  while True:
    dungeon = printing(dungeon,width,height)
    dungeon = moving(dungeon,last_tile_rep,width,height)
    if dungeon == True:
      break
    else:
      last_tile_rep = dungeon[1]
      dungeon = dungeon[0]
  clear()
Ejemplo n.º 48
0
def q2():
     anwser = ask(c.yellow + "What is Jake's favorite video game franchise" + c.yellow)
     if anwser.startswith('pokemon' or 'mother' or 'zelda' or 'earthbound'):
         return True
     return False