Skip to content

Show different rate-limit error while working to fix the issue #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.phar
/vendor/
.env
.env
.vscode/
36 changes: 16 additions & 20 deletions src/demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
<script async src="https://www.googletagmanager.com/gtag/js?id=G-48CYVH0XEF"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-48CYVH0XEF');
</script>
Expand Down Expand Up @@ -41,32 +44,25 @@ function gtag() { dataLayer.push(arguments); }
<!-- GitHub badges/links section -->
<div class="github">
<!-- GitHub Sponsors -->
<a class="github-button" href="https://github.com/sponsors/denvercoder1"
data-color-scheme="no-preference: light; light: light; dark: dark;" data-icon="octicon-heart"
data-size="large" aria-label="Sponsor @denvercoder1 on GitHub">Sponsor</a>
<a class="github-button" href="https://github.com/sponsors/denvercoder1" data-color-scheme="no-preference: light; light: light; dark: dark;" data-icon="octicon-heart" data-size="large" aria-label="Sponsor @denvercoder1 on GitHub">Sponsor</a>
<!-- View on GitHub -->
<a class="github-button" href="https://github.com/denvercoder1/github-readme-streak-stats"
data-color-scheme="no-preference: light; light: light; dark: dark;" data-size="large"
aria-label="View denvercoder1/github-readme-streak-stats on GitHub">View on GitHub</a>
<a class="github-button" href="https://github.com/denvercoder1/github-readme-streak-stats" data-color-scheme="no-preference: light; light: light; dark: dark;" data-size="large" aria-label="View denvercoder1/github-readme-streak-stats on GitHub">View on GitHub</a>
<!-- GitHub Star -->
<a class="github-button" href="https://github.com/denvercoder1/github-readme-streak-stats"
data-color-scheme="no-preference: light; light: light; dark: dark;" data-icon="octicon-star"
data-size="large" data-show-count="true" aria-label="Star denvercoder1/github-readme-streak-stats on GitHub">Star</a>
<a class="github-button" href="https://github.com/denvercoder1/github-readme-streak-stats" data-color-scheme="no-preference: light; light: light; dark: dark;" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star denvercoder1/github-readme-streak-stats on GitHub">Star</a>
</div>

<div class="container">
<div class="properties">
<h2>Properties</h2>
<form class="parameters">
<label for="user">Username<span title="required">*</span></label>
<input class="param" type="text" id="user" name="user" placeholder="DenverCoder1" required
pattern="^[A-Za-z\d-]{0,39}[A-Za-z\d]$" title="Up to 40 letters or hyphens but not ending with hyphen">
<input class="param" type="text" id="user" name="user" placeholder="DenverCoder1" required pattern="^[A-Za-z\d-]{0,39}[A-Za-z\d]$" title="Up to 40 letters or hyphens but not ending with hyphen">

<label for="theme">Theme</label>
<select class="param" id="theme" name="theme" placeholder="default">
<?php foreach ($THEMES as $theme => $options): ?>
<option><?php echo $theme; ?></option>
<?php endforeach;?>
<?php foreach ($THEMES as $theme => $options) : ?>
<option><?php echo $theme; ?></option>
<?php endforeach; ?>
</select>

<label for="hide_border">Hide Border</label>
Expand All @@ -90,9 +86,9 @@ function gtag() { dataLayer.push(arguments); }
<div class="content parameters">
<label for="theme">Add Property</label>
<select id="properties" name="properties" placeholder="background">
<?php foreach ($THEMES["default"] as $option => $color): ?>
<option><?php echo $option; ?></option>
<?php endforeach;?>
<?php foreach ($THEMES["default"] as $option => $color) : ?>
<option><?php echo $option; ?></option>
<?php endforeach; ?>
</select>
<button class="plus btn" onclick="return preview.addProperty();">+</button>
</div>
Expand Down Expand Up @@ -121,8 +117,8 @@ function gtag() { dataLayer.push(arguments); }
</div>

<a href="javascript:toggleTheme()" class="darkmode" title="toggle dark mode">
<i class="<?php echo $_COOKIE["darkmode"] == "on" ? 'gg-sun' : "gg-moon"; ?>"></i>
<i class="<?php echo (isset($_COOKIE["darkmode"]) && $_COOKIE["darkmode"] == "on") ? 'gg-sun' : "gg-moon"; ?>"></i>
</a>
</body>

</html>
</html>
4 changes: 0 additions & 4 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
// get streak stats for user given in query string
$contributionGraphs = getContributionGraphs($_REQUEST["user"]);
$contributions = getContributionDates($contributionGraphs);
// if no contributions, display error
if (count($contributions) === 0) {
throw new AssertionError("No contributions found.");
}
$stats = getContributionStats($contributions);
renderOutput($stats);
} catch (InvalidArgumentException | AssertionError $error) {
Expand Down
8 changes: 8 additions & 0 deletions src/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function getContributionDates(array $contributionGraphs): array
$today = date("Y-m-d");
$tomorrow = date("Y-m-d", strtotime("tomorrow"));
foreach ($contributionGraphs as $graph) {
// if HTML contains "Please wait", we are being rate-limited
if (strpos($graph, "Please wait") !== false) {
throw new AssertionError("Oh no! We are being rate-limited!");
}
// split into lines
$lines = explode("\n", $graph);
// add the dates and contribution counts to the array
Expand Down Expand Up @@ -162,6 +166,10 @@ function getYearJoined(string $user): int
*/
function getContributionStats(array $contributions): array
{
// if no contributions, display error
if (empty($contributions)) {
throw new AssertionError("No contributions found.");
}
$today = array_key_last($contributions);
$first = array_key_first($contributions);
$stats = [
Expand Down