Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AkashD-Developer committed Mar 7, 2021
2 parents 3eb904b + 844ee84 commit 83a6a83
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 50 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@
"contributions": [
"code"
]
},
{
"login": "AkashD-Developer",
"name": "Akash Dhanwani",
"avatar_url": "https://avatars.githubusercontent.com/u/44431401?v=4",
"profile": "https://github.com/AkashD-Developer",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
12 changes: 1 addition & 11 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@ labels: enhancement
assignees: ''
---

**Description**




**Why do you think it would be a good idea?**
<!--remove this section if it is already covered in the description-->



<!--please also state whether or not you would like to work on this if accepted-->
<!--please state whether or not you would like to work on this if accepted-->

---

Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,10 @@ dmypy.json

# Cython debug symbols
cython_debug/

# IDE specific
.DS_Store
.idea/

# Cache file
.cached_result.json
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,26 +269,28 @@ Thanks goes to all of these wonderful people ([emoji key](https://allcontributor
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/Shagilton"><img src="https://avatars0.githubusercontent.com/u/21122143?v=4" width="100px;" alt=""/><br /><sub><b>Shagilton</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=Shagilton" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/hexbee"><img src="https://avatars2.githubusercontent.com/u/26668583?v=4" width="100px;" alt=""/><br /><sub><b>hexbee</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/issues?q=author%3Ahexbee" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/swellander"><img src="https://avatars0.githubusercontent.com/u/22231097?v=4" width="100px;" alt=""/><br /><sub><b>Sam Wellander</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=swellander" title="Code">💻</a></td>
<td align="center"><a href="https://www.shivamsinha.xyz/"><img src="https://avatars0.githubusercontent.com/u/32016929?v=4" width="100px;" alt=""/><br /><sub><b>Shivam Sinha</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=shivam212" title="Code">💻</a></td>
<td align="center"><a href="https://www.willmcgugan.com"><img src="https://avatars3.githubusercontent.com/u/554369?v=4" width="100px;" alt=""/><br /><sub><b>Will McGugan</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=willmcgugan" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ashikjm"><img src="https://avatars1.githubusercontent.com/u/12744524?v=4" width="100px;" alt=""/><br /><sub><b>Ashik J M</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=ashikjm" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ylchao"><img src="https://avatars0.githubusercontent.com/u/15059429?v=4" width="100px;" alt=""/><br /><sub><b>Yu-Lin Chao</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=ylchao" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Shagilton"><img src="https://avatars0.githubusercontent.com/u/21122143?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Shagilton</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=Shagilton" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/hexbee"><img src="https://avatars2.githubusercontent.com/u/26668583?v=4?s=100" width="100px;" alt=""/><br /><sub><b>hexbee</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/issues?q=author%3Ahexbee" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/swellander"><img src="https://avatars0.githubusercontent.com/u/22231097?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sam Wellander</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=swellander" title="Code">💻</a></td>
<td align="center"><a href="https://www.shivamsinha.xyz/"><img src="https://avatars0.githubusercontent.com/u/32016929?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Shivam Sinha</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=shivam212" title="Code">💻</a></td>
<td align="center"><a href="https://www.willmcgugan.com"><img src="https://avatars3.githubusercontent.com/u/554369?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Will McGugan</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=willmcgugan" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ashikjm"><img src="https://avatars1.githubusercontent.com/u/12744524?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ashik J M</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=ashikjm" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ylchao"><img src="https://avatars0.githubusercontent.com/u/15059429?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yu-Lin Chao</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=ylchao" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/Saif807380"><img src="https://avatars2.githubusercontent.com/u/50794619?v=4" width="100px;" alt=""/><br /><sub><b>Saif Kazi</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=Saif807380" title="Code">💻</a> <a href="https://github.com/hedythedev/starcli/commits?author=Saif807380" title="Documentation">📖</a></td>
<td align="center"><a href="http://arcanedomain.duckdns.org"><img src="https://avatars3.githubusercontent.com/u/16456078?v=4" width="100px;" alt=""/><br /><sub><b>arcanearronax</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=arcanearronax" title="Tests">⚠️</a> <a href="https://github.com/hedythedev/starcli/commits?author=arcanearronax" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/jSadoski"><img src="https://avatars1.githubusercontent.com/u/1865629?v=4" width="100px;" alt=""/><br /><sub><b>jSadoski</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=jSadoski" title="Documentation">📖</a> <a href="https://github.com/hedythedev/starcli/commits?author=jSadoski" title="Code">💻</a></td>
<td align="center"><a href="https://www.odmishien.fun"><img src="https://avatars3.githubusercontent.com/u/25533384?v=4" width="100px;" alt=""/><br /><sub><b>odmishien(Tetsuya MISHIMA)</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=odmishien" title="Code">💻</a></td>
<td align="center"><a href="http://linkedin.com/in/ineelshah"><img src="https://avatars1.githubusercontent.com/u/40118578?v=4" width="100px;" alt=""/><br /><sub><b>Neel Shah</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=ineelshah" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/0xflotus"><img src="https://avatars3.githubusercontent.com/u/26602940?v=4" width="100px;" alt=""/><br /><sub><b>0xflotus</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=0xflotus" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Saif807380"><img src="https://avatars2.githubusercontent.com/u/50794619?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Saif Kazi</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=Saif807380" title="Code">💻</a> <a href="https://github.com/hedythedev/starcli/commits?author=Saif807380" title="Documentation">📖</a></td>
<td align="center"><a href="http://arcanedomain.duckdns.org"><img src="https://avatars3.githubusercontent.com/u/16456078?v=4?s=100" width="100px;" alt=""/><br /><sub><b>arcanearronax</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=arcanearronax" title="Tests">⚠️</a> <a href="https://github.com/hedythedev/starcli/commits?author=arcanearronax" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/jSadoski"><img src="https://avatars1.githubusercontent.com/u/1865629?v=4?s=100" width="100px;" alt=""/><br /><sub><b>jSadoski</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=jSadoski" title="Documentation">📖</a> <a href="https://github.com/hedythedev/starcli/commits?author=jSadoski" title="Code">💻</a></td>
<td align="center"><a href="https://www.odmishien.fun"><img src="https://avatars3.githubusercontent.com/u/25533384?v=4?s=100" width="100px;" alt=""/><br /><sub><b>odmishien(Tetsuya MISHIMA)</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=odmishien" title="Code">💻</a></td>
<td align="center"><a href="http://linkedin.com/in/ineelshah"><img src="https://avatars1.githubusercontent.com/u/40118578?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Neel Shah</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=ineelshah" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/0xflotus"><img src="https://avatars3.githubusercontent.com/u/26602940?v=4?s=100" width="100px;" alt=""/><br /><sub><b>0xflotus</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=0xflotus" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/AkashD-Developer"><img src="https://avatars.githubusercontent.com/u/44431401?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Akash Dhanwani</b></sub></a><br /><a href="https://github.com/hedythedev/starcli/commits?author=AkashD-Developer" title="Code">💻</a></td>
</tr>
</table>

<!-- markdownlint-enable -->
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with io.open("README.md", "rt", encoding="utf8") as f:
LONG_DESC = f.read()

VERSION = "2.16.0"
VERSION = "2.17.0"

# This call to setup() does all the work
setup(
Expand Down
98 changes: 74 additions & 24 deletions starcli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import click
import re
import json
import os
from datetime import datetime, timedelta

from .layouts import list_layout, table_layout, grid_layout, shorten_count
from .search import (
Expand All @@ -13,6 +16,11 @@
)


# could be made into config option in the future
CACHED_RESULT_PATH = os.path.dirname(os.path.dirname(__file__)) + "/.cached_result.json"
CACHE_EXPIRATION = 1 # Minutes


@click.command()
@click.option("--lang", "-l", type=str, default="", help="Language filter eg: python")
@click.option(
Expand Down Expand Up @@ -115,30 +123,72 @@ def cli(

debug_requests_on()

if auth and not re.search(".:.", auth): # check authentication format
click.secho(
f"Invalid authentication format: {auth} must be 'username:token'",
fg="bright_red",
)
click.secho(
"Use --help or see: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token",
fg="bright_red",
)
auth = None

if (
not spoken_language and not date_range
): # if filtering by spoken language and date range not required
tmp_repos = search(
lang, created, pushed, stars, topic, user, debug, order, auth
)
else:
tmp_repos = search_github_trending(
lang, spoken_language, order, stars, date_range
)

if not tmp_repos: # if search() returned None
return
tmp_repos = None
options_key = "{lang}_{spoken_language}_{created}_{topic}_{pushed}_{stars}_{order}_{date_range}_{user}".format(
lang=lang,
spoken_language=spoken_language,
created=created,
topic=topic,
pushed=pushed,
stars=stars,
order=order,
date_range=date_range,
user=user,
)

if os.path.exists(CACHED_RESULT_PATH):
with open(CACHED_RESULT_PATH, "r") as f:
json_file = json.load(f)
result = json_file.get(options_key)
if result:
t = result[-1].get("time")
time = datetime.strptime(t, "%Y-%m-%d %H:%M:%S.%f")
diff = datetime.now() - time
if diff < timedelta(minutes=CACHE_EXPIRATION):
if debug:
logger = logging.getLogger(__name__)
logger.debug("Fetching results from cache")

tmp_repos = result

if not tmp_repos: # If cache expired or results not yet cached
if auth and not re.search(".:.", auth): # Check authentication format
click.secho(
f"Invalid authentication format: {auth} must be 'username:token'",
fg="bright_red",
)
click.secho(
"Use --help or see: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token",
fg="bright_red",
)
auth = None

if (
not spoken_language and not date_range
): # if filtering by spoken language and date range not required
tmp_repos = search(
lang, created, pushed, stars, topic, user, debug, order, auth
)
else:
tmp_repos = search_github_trending(
lang, spoken_language, order, stars, date_range
)

if not tmp_repos: # if search() returned None
return
else: # Cache results
tmp_repos.append({"time": str(datetime.now())})
with open(CACHED_RESULT_PATH, "a+") as f:
if os.path.getsize(CACHED_RESULT_PATH) == 0: # file is empty
result_dict = {options_key: tmp_repos}
f.write(json.dumps(result_dict, indent=4))
else: # file is not empty
f.seek(0)
result_dict = json.load(f)
result_dict[options_key] = tmp_repos
f.truncate(0)
f.write(json.dumps(result_dict, indent=4))

repos = tmp_repos[0:limit_results]

if not long_stats: # shorten the stat counts when not --long-stats
Expand Down

0 comments on commit 83a6a83

Please sign in to comment.