Sourcery Starbot ⭐ refactored bwlambert/planetscraper#1
Sourcery Starbot ⭐ refactored bwlambert/planetscraper#1SourceryAI wants to merge 1 commit intobwlambert:masterfrom
Conversation
| # names in the given directory | ||
| listOfFile = os.listdir(dirName) | ||
| allFiles = list() | ||
| allFiles = [] |
There was a problem hiding this comment.
Function getListOfFiles refactored with the following changes:
- Replace list() with [] (
list-literal)
| allFiles = list() | ||
| allFiles = [] | ||
| # Iterate over all the entries | ||
| for entry in listOfFile: | ||
| # Create full path | ||
| fullPath = os.path.join(dirName, entry) | ||
| # If entry is a directory then get the list of files in this directory | ||
| # If entry is a directory then get the list of files in this directory | ||
| if os.path.isdir(fullPath): | ||
| allFiles = allFiles + getListOfFiles(fullPath) | ||
| else: | ||
| if regex.match(fullPath): | ||
| allFiles.append(fullPath) | ||
| elif regex.match(fullPath): | ||
| allFiles.append(fullPath) |
There was a problem hiding this comment.
Function getListOfMetadataFiles refactored with the following changes:
- Replace list() with [] (
list-literal) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
|
|
||
| def get_remaining_quota(): | ||
| leftquota = 0.0 | ||
| leftquota = 0.0 |
There was a problem hiding this comment.
Function get_remaining_quota refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| lbuf = 0.0025#0.01 | ||
| xbuf = lbuf#/2.0 | ||
| mn = 0 | ||
| totalm2 = 0.0 | ||
| for pp in geometryX: | ||
| listarray = [] | ||
| #listarray.append([pp.x, pp.y]) | ||
| listarray.append([pp.x+xbuf, pp.y-lbuf]) | ||
| listarray.append([pp.x-xbuf, pp.y-lbuf]) | ||
| listarray.append([pp.x-xbuf, pp.y+lbuf]) | ||
| listarray.append([pp.x+xbuf, pp.y+lbuf]) # self intersection? | ||
| listarray = [ | ||
| [pp.x + xbuf, pp.y - lbuf], | ||
| [pp.x - xbuf, pp.y - lbuf], | ||
| [pp.x - xbuf, pp.y + lbuf], | ||
| [pp.x + xbuf, pp.y + lbuf], | ||
| ] | ||
|
|
||
| nparray = np.array(listarray) | ||
| poly = geometry.Polygon(nparray) | ||
|
|
There was a problem hiding this comment.
Function calculate_sqkm refactored with the following changes:
- Merge append into list declaration [×4] (
merge-list-append)
This removes the following comments ( why? ):
# self intersection?
#listarray.append([pp.x, pp.y])
|
|
||
| gjlist= [] | ||
| lbuf = 0.01 | ||
| xbuf = lbuf#/2.0 | ||
| mn = 0 | ||
| totalm2 = 0.0 | ||
| for pp in geometryX: | ||
| listarray = [] | ||
| #listarray.append([pp.x, pp.y]) | ||
| listarray.append([pp.x+xbuf, pp.y-lbuf]) | ||
| listarray.append([pp.x-xbuf, pp.y-lbuf]) | ||
| listarray.append([pp.x-xbuf, pp.y+lbuf]) | ||
| listarray.append([pp.x+xbuf, pp.y+lbuf]) # self intersection? | ||
| listarray = [ | ||
| [pp.x + xbuf, pp.y - lbuf], | ||
| [pp.x - xbuf, pp.y - lbuf], | ||
| [pp.x - xbuf, pp.y + lbuf], | ||
| [pp.x + xbuf, pp.y + lbuf], | ||
| ] | ||
|
|
||
| nparray = np.array(listarray) | ||
| poly = geometry.Polygon(nparray) | ||
|
|
There was a problem hiding this comment.
Function generate_geojson_from_coords_df refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Merge append into list declaration [×4] (
merge-list-append) - Replace manual loop counter with call to enumerate (
convert-to-enumerate) - Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
This removes the following comments ( why? ):
#print(json.dumps(g1,indent=1))
#print(mn)
# self intersection?
#listarray.append([pp.x, pp.y])
| result = \ | ||
| requests.get( | ||
| hp, | ||
| auth=HTTPBasicAuth(PLANET_API_KEY, '') | ||
| ) | ||
| return(result) | ||
| return requests.get(hp, auth=HTTPBasicAuth(PLANET_API_KEY, '')) |
There was a problem hiding this comment.
Function get_requestv2_results refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| loc_ids = [] | ||
| for order in r2js['orders']: | ||
| if(order['name']==name): | ||
| loc_ids.append(order["_links"]["_self"]) | ||
| return(loc_ids) | ||
| return [ | ||
| order["_links"]["_self"] | ||
| for order in r2js['orders'] | ||
| if (order['name'] == name) | ||
| ] |
There was a problem hiding this comment.
Function extract_location_ids refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| #dres = spec_result['_links'] | ||
| act_ids = [order['location'] for order in dres['results']] | ||
| return(act_ids) | ||
| return [order['location'] for order in dres['results']] |
There was a problem hiding this comment.
Function get_download_url refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
#dres = spec_result['_links']
| l=gdf.distance(gdf.shift()) | ||
| return(l) | ||
| return gdf.distance(gdf.shift()) |
There was a problem hiding this comment.
Function lldist refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
|
|
||
| print("Loading Planet API key from key.txt") | ||
| with open('key.txt', 'r') as file: | ||
| PLANET_API_KEY = file.read().replace('\n', '') | ||
|
|
||
| locfile = sys.argv[1] | ||
| if locfile == "resume": | ||
| resume_and_sync() | ||
| exit() | ||
| if locfile == "quota": | ||
| get_remaining_quota() | ||
| exit() | ||
|
|
||
| elif locfile == "resume": | ||
| resume_and_sync() | ||
| exit() |
There was a problem hiding this comment.
Lines 564-653 refactored with the following changes:
- Simplify conditional into switch-like form [×3] (
switch) - Move assignment closer to its usage within a block (
move-assign-in-block) - Hoist statements out of for/while loops [×2] (
hoist-statement-from-loop) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups) - Replace manual loop counter with call to enumerate (
convert-to-enumerate)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run: