| Conditions | 8 |
| Total Lines | 65 |
| Code Lines | 61 |
| 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:
| 1 | # -*- coding: utf-8 -*- |
||
| 45 | def process(self): |
||
| 46 | soup = save_downloaded_soup('{}'.format(self.link), os.path.join(self.download_cache, self.filename)) |
||
| 47 | data = [] |
||
| 48 | if soup is not None: |
||
| 49 | # parse the html using beautiful soap and store in variable `soup` |
||
| 50 | table = soup.find('table', attrs={'class': 'tescoce-table'}) |
||
| 51 | table_body = table.find('tbody') |
||
| 52 | rows = table_body.find_all('tr') |
||
| 53 | for row in rows: |
||
| 54 | cols = row.find_all('td') |
||
| 55 | link = cols[0].find('a').get('href') if cols[0].find('a') is not None else [] |
||
| 56 | cols = [element.text.strip() for element in cols] |
||
| 57 | cols[0] = cols[0].split('\n')[0] |
||
| 58 | del cols[-1] |
||
| 59 | del cols[-1] |
||
| 60 | cols.append(link) |
||
| 61 | data.append(cols) |
||
| 62 | for poi_data in data: |
||
| 63 | # Assign: code, postcode, city, name, branch, website, original, street, housenumber, conscriptionnumber, ref, geom |
||
| 64 | street, housenumber, conscriptionnumber = extract_street_housenumber_better_2(poi_data[3]) |
||
| 65 | tesco_replace = re.compile('(expressz{0,1})', re.IGNORECASE) |
||
| 66 | poi_data[0] = tesco_replace.sub('Expressz', poi_data[0]) |
||
| 67 | if 'xpres' in poi_data[0]: |
||
| 68 | name = 'Tesco Expressz' |
||
| 69 | code = 'hutescoexp' |
||
| 70 | elif 'xtra' in poi_data[0]: |
||
| 71 | name = 'Tesco Extra' |
||
| 72 | code = 'hutescoext' |
||
| 73 | else: |
||
| 74 | name = 'Tesco' |
||
| 75 | code = 'hutescosup' |
||
| 76 | poi_data[0] = poi_data[0].replace('TESCO', 'Tesco') |
||
| 77 | poi_data[0] = poi_data[0].replace('Bp.', 'Budapest') |
||
| 78 | postcode = poi_data[1].strip() |
||
| 79 | city = clean_city(poi_data[2].split(',')[0]) |
||
| 80 | branch = poi_data[0] |
||
| 81 | website = poi_data[4] |
||
| 82 | nonstop = None |
||
| 83 | mo_o = None |
||
| 84 | th_o = None |
||
| 85 | we_o = None |
||
| 86 | tu_o = None |
||
| 87 | fr_o = None |
||
| 88 | sa_o = None |
||
| 89 | su_o = None |
||
| 90 | mo_c = None |
||
| 91 | th_c = None |
||
| 92 | we_c = None |
||
| 93 | tu_c = None |
||
| 94 | fr_c = None |
||
| 95 | sa_c = None |
||
| 96 | su_c = None |
||
| 97 | original = poi_data[3] |
||
| 98 | geom = None |
||
| 99 | ref = None |
||
| 100 | insert_data.append( |
||
| 101 | [code, postcode, city, name, branch, website, original, street, housenumber, conscriptionnumber, |
||
| 102 | ref, geom, nonstop, mo_o, tu_o, we_o, th_o, fr_o, sa_o, su_o, mo_c, th_c, we_c, tu_c, fr_c, sa_c, |
||
| 103 | su_c]) |
||
| 104 | if len(insert_data) < 1: |
||
| 105 | logging.warning('Resultset is empty. Skipping ...') |
||
| 106 | else: |
||
| 107 | df = pd.DataFrame(insert_data) |
||
| 108 | df.columns = POI_COLS |
||
| 109 | insert_poi_dataframe(self.session, df) |
||
| 110 |