- 
                Notifications
    You must be signed in to change notification settings 
- Fork 44
Get country and state from a cache #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            CachingFoX
  wants to merge
  10
  commits into
  tomasbedrich:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
CachingFoX:country-state
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      5dfdf5c
              
                new class (and helper class) to handle country and state from a cache
              
              
                 22145fd
              
                extend class Cache to get country and state attribute
              
              
                 83030a0
              
                getter and setter for language of website
              
              
                 651d34e
              
                I18N helper classes for all supported languages
              
              
                 bfd30e4
              
                use I18NHelper to parser pages
              
              
                 fc23f6e
              
                allow kwarg 'country' / fix typo
              
              
                 2ec9c87
              
                fix isort findings
              
              
                 a39aa00
              
                fix black findings
              
              
                 47bcbb4
              
                fix flake8 findings
              
              
                 5ff1c9b
              
                improve docu
              
              
                 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [flake8] | ||
| max-line-length = 120 | ||
| exclude = .venv,dist,docs,build,*.egg,.git,__pycache__ | ||
| exclude = .venv,dist,docs,build,*.egg,.git,__pycache__,.eggs,venv | ||
| count = true | ||
| show-source = true | ||
| statistics = true | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -9,7 +9,9 @@ | |
| from bs4.element import Script | ||
|  | ||
| from pycaching import errors | ||
| from pycaching.country import CountryState | ||
| from pycaching.geo import Point | ||
| from pycaching.i18nhelper import I18NHelperFactory | ||
| from pycaching.log import Log | ||
| from pycaching.log import Type as LogType | ||
| from pycaching.trackable import Trackable | ||
|  | @@ -233,6 +235,7 @@ def __init__(self, geocaching, wp, **kwargs): | |
| "guid", | ||
| "visited", | ||
| "log_counts", | ||
| "country", | ||
| } | ||
|  | ||
| for name in known_kwargs: | ||
|  | @@ -680,6 +683,15 @@ def _trackable_page_url(self): | |
| def _trackable_page_url(self, trackable_page_url): | ||
| self.__trackable_page_url = trackable_page_url | ||
|  | ||
| @property | ||
| @lazy_loaded | ||
| def country(self): | ||
| return self._country | ||
|  | ||
| @country.setter | ||
| def country(self, country): | ||
| self._country = country | ||
|  | ||
| def load(self): | ||
| """Load all possible cache details. | ||
|  | ||
|  | @@ -710,6 +722,9 @@ def load(self): | |
| # probably 404 during cache loading - cache does not exist | ||
| raise errors.LoadError("Error in loading cache") from e | ||
|  | ||
| language = self.geocaching.get_website_language() | ||
| i18nhelper = I18NHelperFactory.create(language) | ||
|  | ||
| # check for PM only caches if using free account | ||
| self.pm_only = root.find("section", "premium-upgrade-widget") is not None | ||
|  | ||
|  | @@ -722,8 +737,7 @@ def load(self): | |
|  | ||
| self.name = cache_details.find("h1").text.strip() | ||
|  | ||
| author = cache_details.find(id="ctl00_ContentBody_uxCacheBy").text | ||
| self.author = author[11:] # 11 = len("A cache by ") | ||
| self.author = i18nhelper.author(cache_details.find(id="ctl00_ContentBody_uxCacheBy").text.strip()) | ||
|  | ||
| # parse cache detail list into a python list | ||
| details = cache_details.find("ul", "ul__hide-details").text.split("\n") | ||
|  | @@ -743,7 +757,8 @@ def load(self): | |
| raise errors.LoadError() | ||
| self.name = cache_details.find("h2").text | ||
|  | ||
| self.author = cache_details("a")[1].text | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this works correctly (for all languages) and shouldn't be removed. | ||
| # TODO self.author = i18nhelper.author().text.strip()) | ||
| self.author = cache_details.find(id="ctl00_ContentBody_mcd1").find("a").text.strip() | ||
|  | ||
| D_and_T_img = root.find("div", "CacheStarLabels").find_all("img") | ||
| self.difficulty, self.terrain = [float(img.get("alt").split()[0]) for img in D_and_T_img] | ||
|  | @@ -772,6 +787,9 @@ def load(self): | |
|  | ||
| self.location = Point.from_string(root.find(id="uxLatLon").text) | ||
|  | ||
| country = root.find(id="ctl00_ContentBody_Location") | ||
| self.country = CountryState.from_string(i18nhelper.country(country.text)) | ||
|  | ||
| self.state = root.find("ul", "OldWarning") is None | ||
|  | ||
| log_image = root.find(id="ctl00_ContentBody_GeoNav_logTypeImage") | ||
|  | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed an obsolete piece of code, replaced by
self.author = cache_details("a")[1].text. Thus it can be deleted without replacement.