|  | @@ -24,7 +24,7 @@ class RRClientException(Exception):
 | 
											
												
													
														|  |      """RR exception"""
 |  |      """RR exception"""
 | 
											
												
													
														|  |      def __init__(self, *args, **kwargs):
 |  |      def __init__(self, *args, **kwargs):
 | 
											
												
													
														|  |          Exception.__init__(self, *args, **kwargs)
 |  |          Exception.__init__(self, *args, **kwargs)
 | 
											
												
													
														|  | -    LOGGER.warning('RRClientException')
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.warning('RRClientException')
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  class Client:
 |  |  class Client:
 | 
											
										
											
												
													
														|  | @@ -207,76 +207,24 @@ class Client:
 | 
											
												
													
														|  |              'value': value,
 |  |              'value': value,
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    def create_article(
 |  | 
 | 
											
												
													
														|  | -            self,
 |  | 
 | 
											
												
													
														|  | -            title,
 |  | 
 | 
											
												
													
														|  | -            article,
 |  | 
 | 
											
												
													
														|  | -            article_lang="en",
 |  | 
 | 
											
												
													
														|  | -            paper_id=0,
 |  | 
 | 
											
												
													
														|  | -            category='0',
 |  | 
 | 
											
												
													
														|  | -            region="4524"
 |  | 
 | 
											
												
													
														|  | -    ):
 |  | 
 | 
											
												
													
														|  | -        """Create new article"""
 |  | 
 | 
											
												
													
														|  | -        response = self.session.get('http://rivalregions.com/#overview')
 |  | 
 | 
											
												
													
														|  | -        response = self.session.post("http://rivalregions.com/news/post", data={
 |  | 
 | 
											
												
													
														|  | -            'c': self.var_c,
 |  | 
 | 
											
												
													
														|  | -            'newspaper': paper_id,
 |  | 
 | 
											
												
													
														|  | -            'category': category,
 |  | 
 | 
											
												
													
														|  | -            'paper': article,
 |  | 
 | 
											
												
													
														|  | -            'title': title,
 |  | 
 | 
											
												
													
														|  | -            'region': region
 |  | 
 | 
											
												
													
														|  | -        })
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    def market_info(self, resource, r_id=False):
 |  | 
 | 
											
												
													
														|  | -        """
 |  | 
 | 
											
												
													
														|  | -        Returns a list of data about current resource market state.
 |  | 
 | 
											
												
													
														|  | -        In form price, amount selling, player id, player name string, total offers on market.
 |  | 
 | 
											
												
													
														|  | -        """
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -        if not r_id:
 |  | 
 | 
											
												
													
														|  | -            res_id = self.resource_id[resource]
 |  | 
 | 
											
												
													
														|  | -        else:
 |  | 
 | 
											
												
													
														|  | -            res_id = resource
 |  | 
 | 
											
												
													
														|  | -        response = self.session.get(f'http://rivalregions.com/storage/market/{res_id}?{self.var_c}')
 |  | 
 | 
											
												
													
														|  | -        return self.parse_market_response(response, res_id)
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    def get_all_market_info(self):
 |  | 
 | 
											
												
													
														|  | -        """Request all market info"""
 |  | 
 | 
											
												
													
														|  | -        session = sessions.FuturesSession(session=self.session)
 |  | 
 | 
											
												
													
														|  | -        results = {}
 |  | 
 | 
											
												
													
														|  | -        for type_ in self.resource_id:
 |  | 
 | 
											
												
													
														|  | -            if type_ == 'energy drink':
 |  | 
 | 
											
												
													
														|  | -                continue
 |  | 
 | 
											
												
													
														|  | -            results[type_] = session.get(
 |  | 
 | 
											
												
													
														|  | -                f'http://rivalregions.com/storage/market/{self.resource_id[type_]}?{self.var_c}'
 |  | 
 | 
											
												
													
														|  | -            )
 |  | 
 | 
											
												
													
														|  | -        for res in results:
 |  | 
 | 
											
												
													
														|  | -            result = results[res].result()
 |  | 
 | 
											
												
													
														|  | -            price, selling_amount, player_id, player_name, total_offers = \
 |  | 
 | 
											
												
													
														|  | -                self.parse_market_response(result, self.resource_id[res])
 |  | 
 | 
											
												
													
														|  | -            results[res] = {
 |  | 
 | 
											
												
													
														|  | -                'price': price,
 |  | 
 | 
											
												
													
														|  | -                'amount': selling_amount,
 |  | 
 | 
											
												
													
														|  | -                'player_id': player_id,
 |  | 
 | 
											
												
													
														|  | -                'player_name': player_name,
 |  | 
 | 
											
												
													
														|  | -                'total_offers':total_offers
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -        return results
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    @staticmethod
 |  | 
 | 
											
												
													
														|  | -    def parse_market_response(response, res_id):
 |  | 
 | 
											
												
													
														|  | -        """Parse market response"""
 |  | 
 | 
											
												
													
														|  | -        price = re.search('<input price="(.*)" type', response.text).group(1)
 |  | 
 | 
											
												
													
														|  | -        selling_amount = re.search('<span max="(.*)" url="', response.text).group(1)
 |  | 
 | 
											
												
													
														|  | -        player_id = re.search(
 |  | 
 | 
											
												
													
														|  | -            '<span action="slide/profile/(.*)" class="storage_see pointer dot hov2', response.text
 |  | 
 | 
											
												
													
														|  | -        ).group(1)
 |  | 
 | 
											
												
													
														|  | -        player_name = re.search(
 |  | 
 | 
											
												
													
														|  | -            f'<span action="slide/profile/{player_id}" class="storage_see pointer dot hov2">(.*)</span>',
 |  | 
 | 
											
												
													
														|  | -            response.text
 |  | 
 | 
											
												
													
														|  | -        ).group(1)
 |  | 
 | 
											
												
													
														|  | -        total_offers = re.search(
 |  | 
 | 
											
												
													
														|  | -            f'Best offer out of <span action="storage/listed/{res_id}" class="storage_see pointer hov2"><span class="dot">(.*)</span></span>:',
 |  | 
 | 
											
												
													
														|  | -            response.text
 |  | 
 | 
											
												
													
														|  | -        ).group(1)
 |  | 
 | 
											
												
													
														|  | -        return price, selling_amount, player_id, player_name, total_offers
 |  | 
 | 
											
												
													
														|  | 
 |  | +    def get(self, path):
 | 
											
												
													
														|  | 
 |  | +        """Send get request to Rival Regions"""
 | 
											
												
													
														|  | 
 |  | +        if path[0] == '/':
 | 
											
												
													
														|  | 
 |  | +            path = path[1:]
 | 
											
												
													
														|  | 
 |  | +        LOGGER.info('GET: %s', path)
 | 
											
												
													
														|  | 
 |  | +        response = self.session.get(
 | 
											
												
													
														|  | 
 |  | +            'http://rivalregions.com/{}'.format(path)
 | 
											
												
													
														|  | 
 |  | +        )
 | 
											
												
													
														|  | 
 |  | +        return response.content
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    def post(self, path, data):
 | 
											
												
													
														|  | 
 |  | +        """Send post request to Rival Regions"""
 | 
											
												
													
														|  | 
 |  | +        if path[0] == '/':
 | 
											
												
													
														|  | 
 |  | +            path = path[1:]
 | 
											
												
													
														|  | 
 |  | +        data['c'] = self.var_c
 | 
											
												
													
														|  | 
 |  | +        LOGGER.info('POST: %s', path)
 | 
											
												
													
														|  | 
 |  | +        response = self.session.post(
 | 
											
												
													
														|  | 
 |  | +            "http://rivalregions.com/{}".format(path),
 | 
											
												
													
														|  | 
 |  | +            data=data
 | 
											
												
													
														|  | 
 |  | +        )
 | 
											
												
													
														|  | 
 |  | +        return response.text
 |