| Conditions | 17 |
| Total Lines | 54 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like osm_poi_matchmaker.dataproviders.hu_omv.hu_omv.process() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- |
||
| 55 | def process(self): |
||
| 56 | try: |
||
| 57 | soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
||
| 58 | self.filetype, self.post) |
||
| 59 | if soup is not None: |
||
| 60 | text = json.loads(soup) |
||
| 61 | for poi_data in text: |
||
| 62 | try: |
||
| 63 | self.data.name = 'OMV' |
||
| 64 | self.data.code = 'huomvfu' |
||
| 65 | if poi_data.get('postcode') is not None and poi_data.get('postcode') != '': |
||
| 66 | self.data.postcode = poi_data.get( |
||
| 67 | 'postcode').strip() |
||
| 68 | if poi_data.get('town_l') is not None and poi_data.get('town_l') != '': |
||
| 69 | self.data.city = clean_city(poi_data.get('town_l')) |
||
| 70 | if poi_data.get('open_hours') is not None: |
||
| 71 | oho, ohc = clean_opening_hours( |
||
| 72 | poi_data.get('open_hours')) |
||
| 73 | if oho == '00:00' and ohc == '24:00': |
||
| 74 | self.data.nonstop = True |
||
| 75 | self.data.public_holiday_open = True |
||
| 76 | oho, ohc = None, None |
||
| 77 | else: |
||
| 78 | self.data.public_holiday_open = False |
||
| 79 | else: |
||
| 80 | oho, ohc = None, None |
||
| 81 | self.data.public_holiday_open = False |
||
| 82 | for i in range(0, 7): |
||
| 83 | self.data.day_open(i, oho) |
||
| 84 | self.data.day_close(i, ohc) |
||
| 85 | self.data.lat, self.data.lon = check_hu_boundary( |
||
| 86 | poi_data.get('y'), poi_data.get('x')) |
||
| 87 | if poi_data.get('address_l') is not None and poi_data.get('address_l') != '': |
||
| 88 | self.data.original = poi_data.get('address_l') |
||
| 89 | self.data.street, self.data.housenumber, self.data.conscriptionnumber = \ |
||
| 90 | extract_street_housenumber_better_2( |
||
| 91 | poi_data.get('address_l')) |
||
| 92 | if poi_data.get('telnr') is not None and poi_data.get('telnr') != '': |
||
| 93 | self.data.phone = clean_phone_to_str( |
||
| 94 | poi_data.get('telnr')) |
||
| 95 | self.data.fuel_octane_95 = True |
||
| 96 | self.data.fuel_diesel = True |
||
| 97 | self.data.fuel_octane_100 = True |
||
| 98 | self.data.fuel_diesel_gtl = True |
||
| 99 | self.data.compressed_air = True |
||
| 100 | self.data.add() |
||
| 101 | except Exception as e: |
||
| 102 | logging.error(e) |
||
| 103 | logging.error(poi_data) |
||
| 104 | logging.exception('Exception occurred') |
||
| 105 | |||
| 106 | except Exception as e: |
||
| 107 | logging.error(e) |
||
| 108 | logging.exception('Exception occurred') |
||
| 109 |