Conditions | 9 |
Total Lines | 59 |
Code Lines | 46 |
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 | import os |
||
17 | def getStations(self): |
||
18 | """ Sends ThriftClient request and writes out received files.""" |
||
19 | req = GetStationsRequest() |
||
20 | req.setPluginName(self.pluginName) |
||
21 | resp = self.client.sendRequest(req) |
||
22 | |||
23 | for i, rec in enumerate(resp): |
||
24 | resp[i] = { |
||
25 | key.decode() if isinstance(key, bytes) else key: |
||
26 | val.decode() if isinstance(val, bytes) else val |
||
27 | for key, val in rec.items() |
||
28 | } |
||
29 | |||
30 | stns = [] |
||
31 | for item in resp: |
||
32 | stationstr = '{:<8}'.format(item.getStationId()) |
||
33 | |||
34 | if sys.byteorder == 'little': |
||
35 | stnid = (ord(stationstr[3]) << 24) + (ord(stationstr[2]) << 16) + \ |
||
36 | (ord(stationstr[1]) << 8) + ord(stationstr[0]) |
||
37 | stnid2 = (ord(stationstr[7]) << 24) + (ord(stationstr[6]) << 16) + \ |
||
38 | (ord(stationstr[5]) << 8) + ord(stationstr[4]) |
||
39 | else: |
||
40 | stnid = (ord(stationstr[0]) << 24) + (ord(stationstr[1]) << 16) + \ |
||
41 | (ord(stationstr[2]) << 8) + ord(stationstr[3]) |
||
42 | stnid2 = (ord(stationstr[4]) << 24) + (ord(stationstr[5]) << 16) + \ |
||
43 | (ord(stationstr[6]) << 8) + ord(stationstr[7]) |
||
44 | |||
45 | if item.getState() is None: |
||
46 | stationstr = ' ' |
||
47 | else: |
||
48 | stationstr = '{:<4}'.format(item.getState()) |
||
49 | |||
50 | if sys.byteorder == 'little': |
||
51 | state = (ord(stationstr[3]) << 24) + (ord(stationstr[2]) << 16) \ |
||
52 | + (ord(stationstr[1]) << 8) + ord(stationstr[0]) |
||
53 | else: |
||
54 | state = (ord(stationstr[0]) << 24) + (ord(stationstr[1]) << 16) \ |
||
55 | + (ord(stationstr[2]) << 8) + ord(stationstr[3]) |
||
56 | |||
57 | stationstr = '{:<4}'.format(item.getCountry()) |
||
58 | if sys.byteorder == 'little': |
||
59 | cntry = (ord(stationstr[3]) << 24) + (ord(stationstr[2]) << 16) \ |
||
60 | + (ord(stationstr[1]) << 8) + ord(stationstr[0]) |
||
61 | else: |
||
62 | cntry = (ord(stationstr[0]) << 24) + (ord(stationstr[1]) << 16) \ |
||
63 | + (ord(stationstr[2]) << 8) + ord(stationstr[3]) |
||
64 | |||
65 | stns.append(9999) |
||
66 | stns.append(stnid) |
||
67 | stns.append(item.getWmoIndex()) |
||
68 | stns.append(int(item.getLatitude()*100)) |
||
69 | stns.append(int(item.getLongitude()*100)) |
||
70 | stns.append(int(item.getElevation())) |
||
71 | stns.append(state) |
||
72 | stns.append(cntry) |
||
73 | stns.append(stnid2) |
||
74 | stns.append(0) |
||
75 | return stns |
||
76 | |||
94 |