Conditions | 23 |
Total Lines | 58 |
Code Lines | 54 |
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_avia.hu_avia.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 -*- |
||
48 | def process(self): |
||
49 | try: |
||
50 | soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename), |
||
51 | self.filetype) |
||
52 | if soup is not None: |
||
53 | # parse the html using beautiful soap and store in variable `soup` |
||
54 | text = json.loads(extract_javascript_variable( |
||
55 | soup, 'markers', True), strict=False) |
||
56 | for poi_data in text: |
||
57 | self.data.name = 'Avia' |
||
58 | self.data.code = 'huaviafu' |
||
59 | if self.data.city is None: |
||
60 | self.data.city = poi_data['title'] |
||
61 | self.data.ref = poi_data['kutid'] if poi_data['kutid'] is not None and poi_data['kutid'] != '' \ |
||
62 | else None |
||
63 | self.data.lat, self.data.lon = check_hu_boundary( |
||
64 | poi_data['lat'], poi_data['lng']) |
||
65 | if poi_data['cim'] is not None and poi_data['cim'] != '': |
||
66 | self.data.postcode, self.data.city, self.data.street, self.data.housenumber, \ |
||
67 | self.data.conscriptionnumber = extract_all_address( |
||
68 | poi_data['cim']) |
||
69 | self.data.website = '/toltoallomas/?id={}'.format(str(poi_data['kutid'])) \ |
||
70 | if poi_data['kutid'] is not None and poi_data['kutid'] != '' else None |
||
71 | self.data.original = poi_data['cim'] |
||
72 | if 'tel' in poi_data and poi_data['tel'] != '': |
||
73 | self.data.phone = clean_phone_to_str(poi_data['tel']) |
||
74 | else: |
||
75 | self.data.phone = None |
||
76 | if 'email' in poi_data and poi_data['email'] != '': |
||
77 | self.data.email = clean_email(poi_data['email']) |
||
78 | else: |
||
79 | self.data.email = None |
||
80 | self.data.public_holiday_open = False |
||
81 | self.data.fuel_octane_95 = True if poi_data.get('b95') == '1' or poi_data.get('b95g') == '1' \ |
||
82 | else False |
||
83 | self.data.fuel_diesel = True if poi_data.get('dies') == '1' or poi_data.get('gdies') == '1' \ |
||
84 | else False |
||
85 | self.data.fuel_octane_98 = True if poi_data.get( |
||
86 | 'b98') == '1' else False |
||
87 | self.data.fuel_lpg = True if poi_data.get( |
||
88 | 'lpg') == '1' else False |
||
89 | self.data.fuel_e85 = True if poi_data.get( |
||
90 | 'e85') == '1' else False |
||
91 | self.data.rent_lpg_bottles = True if poi_data.get( |
||
92 | 'pgaz') == '1' else False |
||
93 | self.data.compressed_air = True if poi_data.get( |
||
94 | 'komp') == '1' else False |
||
95 | self.data.restaurant = True if poi_data.get( |
||
96 | 'etterem') == '1' else False |
||
97 | self.data.food = True if poi_data.get( |
||
98 | 'bufe') == '1' else False |
||
99 | self.data.truck = True if poi_data.get( |
||
100 | 'kpark') == '1' else False |
||
101 | self.data.add() |
||
102 | except Exception as e: |
||
103 | logging.exception('Exception occurred') |
||
104 | |||
105 | logging.error(e) |
||
106 |