class Hifz(models.Model): with open('api/data/surahs.json', 'r', encoding='utf8') as f: surah_data = load(f) surah_array = surah_data['data'] surah_array = tuple(zip(pluck(surah_array, 'number'), pluck(surah_array, 'englishName'))) # user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1, on_delete=models.CASCADE) owner = models.ForeignKey('auth.User', related_name='hifz', on_delete=models.CASCADE) ayat_number = models.IntegerField() surah = models.IntegerField() last_refreshed = models.DateField(default=datetime.date.today) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) def getSurahNameString(self): return self.surah_array[self.surah - 1][1] def getLastRefreshed(self): if (type(self.last_refreshed) != datetime.date): raise TypeError() return self.last_refreshed def setLastRefreshed(self, time): if (type(time) != datetime.date): raise TypeError() self.last_refreshed = time
def get_live_players(): """ Returns table of players which are online (cached players are excluded). """ # TODO: Should return online friends and clan members too players = _battle_players players = players.union(_prebattle_players.where(lambda o: o.id not in _.pluck(players, 'id'))) players = players.union(_me_player.where(lambda o: o.id not in _.pluck(players, 'id'))) return players
def get_live_players(): """ Returns table of players which are online (cached players are excluded). """ # TODO: Should return online friends and clan members too players = _battle_players players = players.union( _prebattle_players.where(lambda o: o.id not in _.pluck(players, 'id'))) players = players.union( _me_player.where(lambda o: o.id not in _.pluck(players, 'id'))) return players
def main(): load_dotenv(dotenv_path='.env') EL_DATABASE_NAME = os.getenv("EL_DBNAME") DATABASE_USER = os.getenv("DBUSER") DATABASE_PASSWORD = os.getenv("DBPASS") DATABASE_HOST = os.getenv("DBHOST") connection = pymysql.connect(host=DATABASE_HOST, user=DATABASE_USER, password=DATABASE_PASSWORD, db=EL_DATABASE_NAME, charset='utf8mb4', use_unicode=True, cursorclass=pymysql.cursors.DictCursor) try: with connection.cursor() as pages_cursor: pages_cursor.execute("SET NAMES utf8mb4;") pages_cursor.execute("SET CHARACTER SET utf8mb4;") pages_cursor.execute("SET character_set_connection=utf8mb4;") with connection.cursor() as mentions_cursor: mentions_cursor.execute("SET NAMES utf8mb4;") mentions_cursor.execute("SET CHARACTER SET utf8mb4;") mentions_cursor.execute( "SET character_set_connection=utf8mb4;") pages, page_count = get_nondisambiguation_pages_having_mentions( pages_cursor) for page in progressbar(pages, max_value=page_count): page_id = page['id'] sorted_mentions = get_page_mentions_by_entity( mentions_cursor, page_id) mention_link_titles = _.pluck(sorted_mentions, 'entity') page_iobes = get_page_iobes(page, sorted_mentions, mention_link_titles) write_page_iobes(page, page_iobes) finally: connection.close()
def chooseDealer(self): self.dealer_id = random.choice(pydash.pluck(self.players, "id")) print(""" =================================== || || || Picking a new dealer... || || || =================================== _____ |A . | _____ | /.\ ||A ^ | _____ |(_._)|| / \ ||A _ | _____ | | || \ / || ( ) ||A_ _ | |____V|| . ||(_'_)||( v )| |____V|| | || \ / | |____V|| . | |____V| The dealer is now Player {} """.format(self.dealer_id))
def get_url_ids_from_inverted_index(word_list): word_ids = _.pluck(word_list, 'word_id') result = [ doc for doc in db.inverted_index.find({"word_id": { "$in": word_ids }}) ] return result
def list_stacks(self, filter=None): ret = [] res = self.client.list_stacks(StackStatusFilter=['UPDATE_COMPLETE', 'CREATE_COMPLETE']) res_stack_list = res['StackSummaries'] while res_stack_list is not None: ret.extend(res_stack_list) next_ = res.get('NextToken', None) if next_: res = self.client.list_stacks(StackStatusFilter=['UPDATE_COMPLETE', 'CREATE_COMPLETE'], NextToken=next_) res_stack_list = res['StackSummaries'] else: res_stack_list = None pluck = pydash.pluck(ret, "StackName") return [stack for stack in pluck if filter and stack.startswith(filter)]
def test_boostrap(self): environments = ['ci', 'prod'] gen_keys = [ "{env}-{app}".format(env=env, app=self.test_deploy_ctx.application) for env in environments ] tempdir = tempfile.mkdtemp() bcommand.do_command(deploy_ctx=self.test_deploy_ctx, environments=environments, destination=tempdir) client = boto3.client('ec2', region_name=self.test_deploy_ctx.region) try: res = client.describe_key_pairs() known = pydash.pluck(res['KeyPairs'], 'KeyName') for key in gen_keys: self.assertTrue(key in known, "Did not generate key - {}".format(key)) finally: for gen_key in gen_keys: client.delete_key_pair(KeyName=gen_key) self.clean_dir(tempdir)
def __get_rev(revs, config): """ Either get a single revision, if `rev_num` is set or return all """ if config.get("rev_num") is not None: __log__.debug("Rev num set. {}".format(config.get("rev_num"))) try: if int(config.get("rev_num")) < len(revs): pos = int(config.get("rev_num")) revToUse = revs[pos] __log__.debug("Pos set. New rev is {}".format(revToUse)) except Exception as err: __log__.debug("Error getting specific rev. Returing all: {}".format(err.message)) elif config.get("rev_list"): __log__.debug("Rev list set. Getting list of revs") revToUse = _.pluck(revs, "revision") else: revToUse = revs return revToUse
def pluck(self, path): """Pluck `path` attribute values from :meth:`all` results and return as list. """ return pyd.pluck(self.all(), path)
def get_user_paired_player_ids(user_unique_id): return _.pluck(_pairings.where(user_unique_id=user_unique_id), 'player_id')
def get_url_ids_from_inverted_index(word_list): word_ids = _.pluck(word_list, 'word_id') result = [doc for doc in db.inverted_index.find({"word_id": {"$in": word_ids}})] return result
def get_page_titles(cursor, page_ids): cursor.execute("SELECT title FROM pages WHERE id IN (" + _.join(page_ids, ',') + ")") return _.pluck(cursor.fetchall(), 'title')
def test_pluck(case, filter_by, expected): assert _.pluck(case, filter_by) == expected
def test_pluck(case, expected): assert _.pluck(*case) == expected
def _scrape(self, **kwargs): runner = WebdriverRunner() cases_results = runner.run(WebdriverSteps().go_to_url( self.CASES_DASHBOARD_URL).wait_for_number_of_elements( (By.XPATH, "//div[@class='badge-content-shield']"), 10).wait_for_presence_of_elements( (By.XPATH, '//summary-number')).find_request( key='cases', find_by=lambda r: self.CASES_CARD_PATH in r.path ).find_request(key='cases_by_race', find_by=lambda r: self.AA_CASES_CARD_PATH in r.path).get_page_source()) deaths_results = runner.run(WebdriverSteps().go_to_url( self.DEATHS_DASHBOARD_URL).wait_for_number_of_elements( (By.XPATH, "//div[@class='kpi_chart']"), 14).find_request( key='deaths', find_by=lambda r: self.DEATHS_CARD_PATH in r.path ).find_request( key='deaths_by_race', find_by=lambda r: self.AA_DEATHS_CARD_PATH in r.path)) date = self.get_date(cases_results.page_source) # total cases assert cases_results.requests['cases'] case_data = self.load_response_json(cases_results, 'cases') cases_rows = self.extract_rows(case_data) cases = sum(pydash.pluck(cases_rows, 1)) # aa cases assert cases_results.requests['cases_by_race'] cases_by_race_data = self.load_response_json(cases_results, 'cases_by_race') cases_by_race_rows = self.extract_rows(cases_by_race_data) aa_row = pydash.find( cases_by_race_rows, lambda r: r[0] == 'Black or African-American') or [] assert len(aa_row) == 2, 'Row is malformed' aa_cases = aa_row[1] # total deaths deaths_data = self.load_response_json(deaths_results, 'deaths') deaths_rows = self.extract_rows(deaths_data) deaths = sum(pydash.pluck(deaths_rows, 1)) # aa_deaths deaths_by_race_data = self.load_response_json(deaths_results, 'deaths_by_race') deaths_by_race_rows = self.extract_rows(deaths_by_race_data) aa_deaths_row = pydash.find( deaths_by_race_rows, lambda r: r[0] == 'Black or African-American') or [] assert len(aa_deaths_row) == 2, 'Row is malformed' aa_deaths = aa_deaths_row[1] pct_aa_deaths = to_percentage(aa_deaths, deaths) pct_aa_cases = to_percentage(aa_cases, cases) return [ self._make_series(date=date, cases=cases, deaths=deaths, aa_cases=aa_cases, aa_deaths=aa_deaths, pct_aa_cases=pct_aa_cases, pct_aa_deaths=pct_aa_deaths, pct_includes_unknown_race=True, pct_includes_hispanic_black=True) ]
def func(total, field): total.extend(pydash.pluck(records, field)) return total
def pluck(self, column): """Pluck `column` attribute values from :meth:`all` results and return as list. """ return pyd.pluck(self.all(), column)
import json import pydash import sys resultsfile = open('github-names.csv', 'a') openedfile = open("./data/users.json", "r") jsonstring = "" readfile = openedfile.readlines() for string in readfile: jsonstring += string data = json.loads(jsonstring) results = pydash.pluck(data, 'login') results = ",".join(results) resultsfile.write(results) openedfile.close() resultsfile.close()