Skip to content

Commit a2a7648

Browse files
authored
Show different rate-limit error while working to fix the issue (#179)
1 parent 7e3c7e9 commit a2a7648

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
composer.phar
22
/vendor/
3-
.env
3+
.env
4+
.vscode/

src/demo/index.php

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
<script async src="https://www.googletagmanager.com/gtag/js?id=G-48CYVH0XEF"></script>
1212
<script>
1313
window.dataLayer = window.dataLayer || [];
14-
function gtag() { dataLayer.push(arguments); }
14+
15+
function gtag() {
16+
dataLayer.push(arguments);
17+
}
1518
gtag('js', new Date());
1619
gtag('config', 'G-48CYVH0XEF');
1720
</script>
@@ -41,32 +44,25 @@ function gtag() { dataLayer.push(arguments); }
4144
<!-- GitHub badges/links section -->
4245
<div class="github">
4346
<!-- GitHub Sponsors -->
44-
<a class="github-button" href="https://github.com/sponsors/denvercoder1"
45-
data-color-scheme="no-preference: light; light: light; dark: dark;" data-icon="octicon-heart"
46-
data-size="large" aria-label="Sponsor @denvercoder1 on GitHub">Sponsor</a>
47+
<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>
4748
<!-- View on GitHub -->
48-
<a class="github-button" href="https://github.com/denvercoder1/github-readme-streak-stats"
49-
data-color-scheme="no-preference: light; light: light; dark: dark;" data-size="large"
50-
aria-label="View denvercoder1/github-readme-streak-stats on GitHub">View on GitHub</a>
49+
<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>
5150
<!-- GitHub Star -->
52-
<a class="github-button" href="https://github.com/denvercoder1/github-readme-streak-stats"
53-
data-color-scheme="no-preference: light; light: light; dark: dark;" data-icon="octicon-star"
54-
data-size="large" data-show-count="true" aria-label="Star denvercoder1/github-readme-streak-stats on GitHub">Star</a>
51+
<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>
5552
</div>
5653

5754
<div class="container">
5855
<div class="properties">
5956
<h2>Properties</h2>
6057
<form class="parameters">
6158
<label for="user">Username<span title="required">*</span></label>
62-
<input class="param" type="text" id="user" name="user" placeholder="DenverCoder1" required
63-
pattern="^[A-Za-z\d-]{0,39}[A-Za-z\d]$" title="Up to 40 letters or hyphens but not ending with hyphen">
59+
<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">
6460

6561
<label for="theme">Theme</label>
6662
<select class="param" id="theme" name="theme" placeholder="default">
67-
<?php foreach ($THEMES as $theme => $options): ?>
68-
<option><?php echo $theme; ?></option>
69-
<?php endforeach;?>
63+
<?php foreach ($THEMES as $theme => $options) : ?>
64+
<option><?php echo $theme; ?></option>
65+
<?php endforeach; ?>
7066
</select>
7167

7268
<label for="hide_border">Hide Border</label>
@@ -90,9 +86,9 @@ function gtag() { dataLayer.push(arguments); }
9086
<div class="content parameters">
9187
<label for="theme">Add Property</label>
9288
<select id="properties" name="properties" placeholder="background">
93-
<?php foreach ($THEMES["default"] as $option => $color): ?>
94-
<option><?php echo $option; ?></option>
95-
<?php endforeach;?>
89+
<?php foreach ($THEMES["default"] as $option => $color) : ?>
90+
<option><?php echo $option; ?></option>
91+
<?php endforeach; ?>
9692
</select>
9793
<button class="plus btn" onclick="return preview.addProperty();">+</button>
9894
</div>
@@ -121,8 +117,8 @@ function gtag() { dataLayer.push(arguments); }
121117
</div>
122118

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

128-
</html>
124+
</html>

src/index.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
// get streak stats for user given in query string
3838
$contributionGraphs = getContributionGraphs($_REQUEST["user"]);
3939
$contributions = getContributionDates($contributionGraphs);
40-
// if no contributions, display error
41-
if (count($contributions) === 0) {
42-
throw new AssertionError("No contributions found.");
43-
}
4440
$stats = getContributionStats($contributions);
4541
renderOutput($stats);
4642
} catch (InvalidArgumentException | AssertionError $error) {

src/stats.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ function getContributionDates(array $contributionGraphs): array
6565
$today = date("Y-m-d");
6666
$tomorrow = date("Y-m-d", strtotime("tomorrow"));
6767
foreach ($contributionGraphs as $graph) {
68+
// if HTML contains "Please wait", we are being rate-limited
69+
if (strpos($graph, "Please wait") !== false) {
70+
throw new AssertionError("Oh no! We are being rate-limited!");
71+
}
6872
// split into lines
6973
$lines = explode("\n", $graph);
7074
// add the dates and contribution counts to the array
@@ -162,6 +166,10 @@ function getYearJoined(string $user): int
162166
*/
163167
function getContributionStats(array $contributions): array
164168
{
169+
// if no contributions, display error
170+
if (empty($contributions)) {
171+
throw new AssertionError("No contributions found.");
172+
}
165173
$today = array_key_last($contributions);
166174
$first = array_key_first($contributions);
167175
$stats = [

0 commit comments

Comments
 (0)