def test_cards_indv_call(self): try: api = sep_api mycall = api.cards() mycall.individual_cards(1, 1) mycall.individual_cards(1, 1, full_response=True) mycall.individual_cards(1, 1, 'trades') mycall.individual_cards(1, 1, ns.Shard('trades')) mycall.individual_cards(1, 1, (ns.Shard('trades'), )) # mycall.get_shards(choice(mycall.auto_shards)) # mycall.get_shards(choice(mycall.auto_shards), full_response=True) except Exception as Err: raise Err self.fail(Err)
def census_score_history(self, scales=None): """ Returns the history of weighted census scores for the nation. Return format is (timestamp, scores) where timestamp is a list of unix timestamp and scores a list of scores. these can be plotted using a module like matplotlib to view trends in the nation's score""" if not scales: scales = list(range(65)) + list(range(67, 80)) + [85] # Z-day and WA-stats as well as Residency removed as these make the data really unclear response = self.nation.get_shards(ns.Shard("census", scale=scales, mode="history")) min_ts = 1e100 max_ts = 0 for scale in response.census.scale: for point in scale.point: ts = int(point.timestamp) if ts < min_ts: min_ts = ts if ts > max_ts: max_ts = ts if max_ts == 0: return # something went wrong x = np.arange(min_ts, max_ts, 24*60**2) y = np.array([0. for o in x]) for scale in response.census.scale: c_id = int(scale.id) # we must use interpolation as the timestamps aren't always the same for all scales interp_x = np.array([int(p.timestamp) for p in scale.point]) interp_y = self.census_weights[c_id] * np.array([float(p.score) for p in scale.point]) # Black market does something odd on 2019-11-19 (see https://www.nationstates.net/page=news/2019/index.html) # We need to adjust for this (the other changes are more negligible) if c_id == 79: i = 0 while i < len(interp_x) and interp_x[i] < 1574164800: i += 1 interp_y[:i] /= 6 # this is an approximation and the exact number will vary for all nations. a jump will still be seen, but that is fine y += np.interp(x, interp_x, interp_y) return x, y
def test_shard(self): self.assertEqual( core.Shard("numnations")._get_main_value(), "numnations")
def test_shard_eq(self): self.assertEqual(core.Shard("TEST"), core.Shard("TEST"))
def test_shard_string(self): try: str(core.Shard("TEST")) core.Shard("TEST").name except: self.fail()
def test_shard_repr(self): self.assertIsInstance(core.Shard("test").__repr__(), str) self.assertIsInstance(core.Shard("test", test="test").__repr__(), str)
def test_shard_tail_gen(self): self.assertEqual( core.Shard("dispatch", dispatchid="1").tail_gen(), {"dispatchid": "1"})
reg = api.region(rnamef) pid = '0' if sid == '' else sid start = '\nArchive starts from Post ID ' + pid + ' as Post ' + str( n ) + '\n' + '=' * 80 if pid != '0' or n != 1 else '' # Adds archive start info to heading #Prints the heading to the file. f.write( '=' * 80 + '\n' + rname + ' NationStates RMB Archive\non ' + nt + '\n' + '=' * 80 + '\nPython script by Merni\npynationstates API wrapper by DolphDev (github)/United Island Tribes (NS)\n' + '=' * 80 + start) while True: #Gets messages as list 'msgs' of dicts shd = ns.Shard('messages', limit='100', fromid=str(int(pid) + 1)) x = reg.get_shards(shd) if x['messages'] == None or x['messages']['post'] == None: break msgs = x['messages']['post'] for i in msgs: #unpacks individual attributes of each message (i) and processed them to be ready to write t = int(i['timestamp']) dt = datetime.utcfromtimestamp(t).strftime('%Y-%m-%d at %H:%M:%S UTC') #Previous line by 'rkachach' at Stack Overflow poster = i['nation'] pid = i['id'] likes = int(i['likes']) status = int(i['status']) if likes != 0: likers = i['likers']