GeezerVison is showing github.com — Load the live lion counter on the GitHub profile · mxsm/mxsm@63501ac
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/profile-3d.yml -6Lines changed: 0 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 35 | 35 | python3 -B scripts/update_profile.py contributions | 36 | 36 | git add -- resource/generated/contributions.{json,svg} | 37 | 37 |
| 38 | | - - name: Refresh the Foshan lion view counter | 39 | | - if: ${{ !cancelled() && steps.checkout.outcome == 'success' }} | 40 | | - run: | | 41 | | - python3 -B scripts/update_profile.py profile-views | 42 | | - git add -- resource/generated/profile-views.{json,svg} | 43 | | -
| 44 | 38 | - name: Publish successfully generated cards | 45 | 39 | if: ${{ !cancelled() && steps.checkout.outcome == 'success' && github.ref_type == 'branch' }} | 46 | 40 | run: | | |
Collapse file Copy file name to clipboardExpand all lines: README.md +1-2Lines changed: 1 addition & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -50,10 +50,9 @@ I’m a Java and Rust developer living in Foshan and working in Guangzhou. I gra | 50 | 50 | </a> | 51 | 51 | --> | 52 | 52 |
| 53 | | -<!-- The original counter still records image requests. The lion card displays its daily total. --> | 54 | 53 | <p align="center"> | 55 | 54 | <a href="./resource/generated/languages.svg"><img src="./resource/generated/languages.svg" alt="Most used languages by share of code, updated monthly" width="49%" /></a> | 56 | | - <a href="./resource/generated/profile-views.svg"><img src="./resource/generated/profile-views.svg" alt="Profile views since July 30, 2023, displayed by Foshan lions on drums and updated daily" width="49%" /></a><img src="https://count.getloli.com/get/@:mxsm?theme=normal-1" alt="" width="1" height="1" /> | | 55 | + <a href="https://github-readme-stats-mxsm.vercel.app/api/profile-views"><img src="https://github-readme-stats-mxsm.vercel.app/api/profile-views" alt="Live profile views since July 30, 2023, displayed by Foshan lions on drums" width="49%" /></a> | 57 | 56 | </p> | 58 | 57 |
| 59 | 58 | [](./resource/generated/contributions.svg) | |
Collapse file Copy file name to clipboardExpand all lines: scripts/view_counter.py +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,6 +43,8 @@ def read_counter_image(url): | 43 | 43 |
| 44 | 44 |
| 45 | 45 | def displayed_total(owner): | | 46 | + if owner == "mxsm": | | 47 | + return read_counter_image(original_counter_image()) | 46 | 48 | page = f"https://github.com/{quote(owner, safe='')}" | 47 | 49 | return read_counter_image(counter_image_url(owner, page)) | 48 | 50 |
| @@ -76,7 +78,7 @@ def fetch_views(owner, now): | 76 | 78 | count = series_total(owner) | 77 | 79 | source = "counter-api" | 78 | 80 | except (URLError, TimeoutError) as error: | 79 | | - print(f"Counter API unavailable ({error}). Reading the counter image from the GitHub profile.") | | 81 | + print(f"Counter API unavailable ({error}). Reading the published counter image.") | 80 | 82 | count = displayed_total(owner) | 81 | 83 | source = "profile-counter-image" | 82 | 84 | return {"owner": owner, "updated_at": now.isoformat(), "count": count, "source": source} |
Collapse file Copy file name to clipboardExpand all lines: tests/test_views.py +14-2Lines changed: 14 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,10 @@ class ProfileViewsTest(unittest.TestCase): | 21 | 21 | legacy = "https://count.getloli.com/get/@:mxsm?theme=gelbooru-h" | 22 | 22 | camo = "https://camo.githubusercontent.com/" + "a" * 64 + "/" + legacy.encode().hex() | 23 | 23 |
| | 24 | + def setUp(self): | | 25 | + view_counter.original_counter_image.cache_clear() | | 26 | + self.addCleanup(view_counter.original_counter_image.cache_clear) | | 27 | + | 24 | 28 | def profile_html(self): | 25 | 29 | return io.BytesIO(f'''<article class="markdown-body"> | 26 | 30 | <img src="https://github.com/mxsm/mxsm/raw/main/resource/generated/profile-views.svg" /> | @@ -33,14 +37,22 @@ def counter_svg(self, refs): | 33 | 37 | return io.BytesIO(f'''<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | 34 | 38 | <defs><image id="0" /><image id="3" /><image id="4" /></defs><g>{uses}</g></svg>'''.encode()) | 35 | 39 |
| 36 | | - def test_blocked_series_reads_profile_counter_digits_in_order(self): | | 40 | + def test_blocked_series_reads_counter_from_pinned_readme_in_digit_order(self): | 37 | 41 | forbidden = HTTPError(self.legacy, 403, "Forbidden", {}, io.BytesIO()) | 38 | 42 | self.addCleanup(forbidden.close) | 39 | 43 | svg = self.counter_svg(["#0", "#0", "#3", "#0", "#0", "#3", "#4"]) | 40 | 44 | with patch.object(view_counter, "urlopen", side_effect=[forbidden, self.profile_html(), svg]) as fetch: | 41 | 45 | snapshot = view_counter.fetch_views("mxsm", self.now) | 42 | 46 | self.assertEqual((snapshot["count"], snapshot["source"]), (30034, "profile-counter-image")) | 43 | | - self.assertEqual([call.args[0] for call in fetch.call_args_list[1:]], ["https://github.com/mxsm", self.camo]) | | 47 | + readme = fetch.call_args_list[1].args[0] | | 48 | + self.assertRegex(readme.full_url, r"^https://api\.github\.com/repos/mxsm/mxsm/readme\?ref=[a-f0-9]{40}$") | | 49 | + self.assertEqual(readme.get_header("Accept"), "application/vnd.github.html+json") | | 50 | + self.assertEqual(fetch.call_args_list[2].args[0], self.camo) | | 51 | + | | 52 | + def test_other_owner_reads_counter_from_their_current_profile(self): | | 53 | + with patch.object(view_counter, "urlopen", side_effect=[self.profile_html(), self.counter_svg(["#4"])]) as fetch: | | 54 | + self.assertEqual(view_counter.displayed_total("other"), 4) | | 55 | + self.assertEqual([call.args[0] for call in fetch.call_args_list], ["https://github.com/other", self.camo + "-other"]) | 44 | 56 |
| 45 | 57 | def test_bad_displayed_digit_preserves_published_counter(self): | 46 | 58 | with TemporaryDirectory() as folder: | |
|