Repository: IonicaBizau/ghcal Branch: master Commit: cfc4a23638b8 Files: 11 Total size: 17.3 KB Directory structure: gitextract_7hrvhrbc/ ├── .github/ │ └── FUNDING.yml ├── .gitignore ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── LICENSE ├── README.md ├── bin/ │ └── ghcal ├── example/ │ └── index.js ├── lib/ │ └── index.js ├── package.json └── snap/ └── snapcraft.yaml ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ github: ionicabizau patreon: ionicabizau open_collective: ionicabizau custom: https://www.buymeacoffee.com/h96wwchmy ================================================ FILE: .gitignore ================================================ *.swp *.swo *~ *.log node_modules *.env .DS_Store package-lock.json .bloggify/* ================================================ FILE: CONTRIBUTING.md ================================================ # 🌟 Contributing Want to contribute to this project? Great! Please read these quick steps to streamline the process and avoid unnecessary tasks. ✨ ## 💬 Discuss Changes Start by opening an issue in the repository using the [bug tracker][1]. Describe your proposed contribution or the bug you've found. If relevant, include platform info and screenshots. 🖼️ Wait for feedback before proceeding unless the fix is straightforward, like a typo. 📝 ## 🔧 Fixing Issues Fork the project and create a branch for your fix, naming it `some-great-feature` or `some-issue-fix`. Commit changes while following the [code style][2]. If the project has tests, add one. ✅ If a `package.json` or `bower.json` exists, add yourself to the `contributors` array; create it if it doesn't. 🙌 ```json { "contributors": [ "Your Name (http://your.website)" ] } ``` ## 📬 Creating a Pull Request Open a pull request and reference the initial issue (e.g., *fixes #*). Provide a clear title and consider adding visual aids for clarity. 📊 ## ⏳ Wait for Feedback Your contributions will be reviewed. If feedback is given, update your branch as needed, and the pull request will auto-update. 🔄 ## 🎉 Everyone Is Happy! Your contributions will be merged, and everyone will appreciate your effort! 😄❤️ Thanks! 🤩 [1]: /issues [2]: https://github.com/IonicaBizau/code-style ================================================ FILE: DOCUMENTATION.md ================================================ ## Documentation You can see below the API reference of this module. ### `GhCal(username)` Fetches the GitHub contributions calendar data (in JSON format). #### Params - **String|Object** `username`: The username or an object containing: - `username` (String): The GitHub username. - `cookie` (String): An optional cookie. Could be useful to get the private calendar stats. #### Return - **Request** The request stream. ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2015-25 Ionică Bizău (https://ionicabizau.net) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ [![ghcal](http://i.imgur.com/yzElGZN.png)](#) # `$ ghcal` [![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/ghcal.svg)](https://www.npmjs.com/package/ghcal) [![Downloads](https://img.shields.io/npm/dt/ghcal.svg)](https://www.npmjs.com/package/ghcal) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github) Buy Me A Coffee > See the GitHub contributions calendar of a user in the command line. If you want to track all your git commits (even if you don't push them anywhere), you should [check out the `git-stats` project](https://github.com/IonicaBizau/git-stats). [![ghcal](http://i.imgur.com/OhgCb8o.png)](#) ## :cloud: Installation You can install the package globally and use it as command line tool: ```sh # Using npm npm install --global ghcal # Using yarn yarn global add ghcal ``` Then, run `ghcal --help` and see what the CLI tool can do. ``` $ ghcal --help Usage: ghcal [options] Options: -u, --username The GitHub username. If you're using CLI GitHub, by default it will be your username. -c, --cookie Your GitHub cookie. Useful to get private stats. -s, --since Optional start date. -e, --until Optional end date. -n, --no-ansi Forces the tool not to use ANSI styles. -l, --light Enables the light theme. -h, --help Displays this help. -v, --version Displays version information. Examples: ghcal -u ionicabizau ghcal -u ionicabizau --light ghcal -u ionicabizau --no-ansi ghcal -u ionicabizau -s '1 January 2015' # All the commits from 1 January 2015 to now ghcal -u ionicabizau -s '1 January 2015' -e '1 March 2015' # Select a time range Note that only the last year statistics are available. Documentation can be found at https://github.com/IonicaBizau/ghcal ``` ## Usage ### Default behavior If you are already using [`cli-github`](https://github.com/IonicaBizau/cli-github), then your GitHub username is kept into `~/.github-config.json` and `ghcal` will use it if you don't pass another username: `ghcal` will be the same with `ghcal -u `. ```sh ghcal ``` ### Passing the username Using the `-u` (or `--username`) option, you can specify the GitHub username: ```sh # Fetches the izuzak's contributions $ ghcal -u izuzak ``` ### Themes If you pass the `--light` option, then the light theme will be activated (the default theme is dark). ```sh # jlord's contributions, light theme $ ghcal jlord --light ``` ### No ANSI styles The `--no-ansi` option disables any colors in the output. Unicode characters, without colors will be used. ```sh # @pengywynn's contributions, but without ANSI styles $ ghcal pengwynn --no-ansi ``` ## :clipboard: Example Here is an example how to use this package as library. To install it locally, as library, you can use `npm install ghcal` (or `yarn add ghcal`): ```js var GhCal = require("ghcal"); GhCal("ionicabizau", function (err, data) { console.log(err || data); }); ``` ## :question: Get Help There are few ways to get help: 1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question. 2. For bug reports and feature requests, open issues. :bug: 3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket: ## :memo: Documentation For full API reference, see the [DOCUMENTATION.md][docs] file. ## :yum: How to contribute Have an idea? Found a bug? See [how to contribute][contributing]. ## :sparkling_heart: Support my projects I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it). However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it: - Starring and sharing the projects you like :rocket: - [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book: - [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea: - [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone). - **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6` ![](https://i.imgur.com/z6OQI95.png) Thanks! :heart: ## :dizzy: Where is this library used? If you are using this library in one of your projects, add it in this list. :sparkles: - `github-stats` ## :scroll: License [MIT][license] © [Ionică Bizău][website] [license]: /LICENSE [website]: https://ionicabizau.net [contributing]: /CONTRIBUTING.md [docs]: /DOCUMENTATION.md [badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg [badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg [badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg [badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg [patreon]: https://www.patreon.com/ionicabizau [amazon]: http://amzn.eu/hRo9sIZ [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW ================================================ FILE: bin/ghcal ================================================ #!/usr/bin/env node // Dependencies var GhCal = require("../lib") , GhConfig = {} , Abs = require("abs") , CliGhCal = require("cli-gh-cal") , Logger = require("bug-killer") , Clp = require("clp") , Package = require("../package") , ReadJson = require("r-json") , Moment = require("moment") ; // Try to get the GitHub config username Moment.suppressDeprecationWarnings = true; try { GhConfig = ReadJson(Abs("~/.github-config.json")); } catch (e) {} // Parse the command line arguments var usernameOpt = new Clp.Option(["u", "username"], "The GitHub username. If you're using CLI GitHub, by default it will be your username.", "username", GhConfig.username) , cookieOpt = new Clp.Option(["c", "cookie"], "Your GitHub cookie. Useful to get private stats.", "cookie") , sinceDateOpt = new Clp.Option(["s", "since"], "Optional start date.", "date") , untilDateOpt = new Clp.Option(["e", "until"], "Optional end date.", "date") , noAnsiOpt = new Clp.Option(["n", "no-ansi"], "Forces the tool not to use ANSI styles.") , lightOpt = new Clp.Option(["l", "light"], "Enables the light theme.") , parser = new Clp({ name: "GitHub Calendar" , version: Package.version , exe: Package.name , examples: [ "ghcal -u ionicabizau" , "ghcal -u ionicabizau --light" , "ghcal -u ionicabizau --no-ansi" , "ghcal -u ionicabizau -s '1 January 2015' # All the commits from 1 January 2015 to now" , "ghcal -u ionicabizau -s '1 January 2015' -e '1 March 2015' # Select a time range" ] , docs_url: Package.homepage , notes: "Note that only the last year statistics are available." , process: true }, [ usernameOpt , cookieOpt , sinceDateOpt , untilDateOpt , noAnsiOpt , lightOpt ]) ; // Stringify the stats GhCal({ username: usernameOpt.value , cookie: cookieOpt.value }, function (err, data) { if (err) { return Logger.log(err, "error"); } console.log(CliGhCal(data, { theme: lightOpt.is_provided ? "LIGHT" : noAnsiOpt.is_provided ? null : "DARK" , start: sinceDateOpt.value ? Moment(sinceDateOpt.value) : null , end: untilDateOpt.value ? Moment(untilDateOpt.value) : null })); }); ================================================ FILE: example/index.js ================================================ var GhCal = require("../lib"); GhCal("ionicabizau", function (err, data) { console.log(err || data); }); ================================================ FILE: lib/index.js ================================================ // Dependencies var Cheerio = require("cheerio") , Request = require("request") , Typpy = require("typpy") ; /** * GhCal * Fetches the GitHub contributions calendar data (in JSON format). * * @name GhCal * @function * @param {String|Object} username The username or an object containing: * * - `username` (String): The GitHub username. * - `cookie` (String): An optional cookie. Could be useful to get the private calendar stats. * * @return {Request} The request stream. */ var GhCal = module.exports = function (options, callback) { if (Typpy(options, String)) { options = { username: options }; } if (!options.username || !Typpy(options.username, String)) { return callback(new Error("Invalid username.")); } var url = "http://github.com/users/" + options.username + "/contributions" , headers = {} ; if (options.cookie) { headers["Cookie"] = options.cookie; } return Request({ url: url , headers: headers }, function (err, res, body) { if (err) { return callback(err); } if (res.statusCode === 404) { return callback(new Error("User doesn't exist.")); } if (res.statusCode !== 200) { return callback(new Error("Cannot fetch data for this user.")); } var $ = Cheerio.load(body) , $g = $("g > g") , $cRect = null , $rect = null , y = 0 , resData = [] , cDate = "" , cCount = null , cColor = "" , cMonth = null , monthHack = "MMM" ; for (; y < 7; ++y) { $g.each(function (i) { $rect = $("rect", this).eq(y) if (!$rect) { return; } cDate = $rect.attr("data-date"); cCount = parseInt($rect.attr("data-count")); if (!cDate || isNaN(cCount)) { return; } resData.push([ cDate , cCount ]); }); } callback(null, resData); }); }; ================================================ FILE: package.json ================================================ { "name": "ghcal", "version": "2.3.13", "description": "See the GitHub contributions calendar of a user in the command line.", "main": "lib/index.js", "bin": { "ghcal": "./bin/ghcal" }, "scripts": { "test": "node test" }, "repository": { "type": "git", "url": "git+ssh://git@github.com/IonicaBizau/ghcal.git" }, "keywords": [ "github", "contributions", "command", "line" ], "author": "Ionică Bizău (https://ionicabizau.net)", "license": "MIT", "bugs": { "url": "https://github.com/IonicaBizau/ghcal/issues" }, "homepage": "https://github.com/IonicaBizau/ghcal", "dependencies": { "abs": "^1.0.0", "ansi-parser": "^3.0.0", "bug-killer": "^4.0.0", "cheerio": "0.22.0", "cli-box": "^5.0.0", "cli-gh-cal": "^1.0.0", "clp": "^3.0.0", "git-stats-colors": "^2.1.0", "moment": "^2.10.6", "r-json": "^1.0.0", "request": "^2.53.0", "typpy": "^2.1.2", "ul": "^5.0.0" }, "devDependencies": {}, "blah": { "h_img": "http://i.imgur.com/yzElGZN.png", "ex_img": "http://i.imgur.com/OhgCb8o.png", "description": "If you want to track all your git commits (even if you don't push them anywhere), you should [check out the `git-stats` project](https://github.com/IonicaBizau/git-stats).", "installation": [ { "h2": "Usage" }, { "h3": "Default behavior" }, { "p": "If you are already using [`cli-github`](https://github.com/IonicaBizau/cli-github), then your GitHub username is kept into `~/.github-config.json` and `ghcal` will use it if you don't pass another username: `ghcal` will be the same with `ghcal -u `." }, { "code": { "language": "sh", "content": "ghcal" } }, { "h3": "Passing the username" }, { "p": " Using the `-u` (or `--username`) option, you can specify the GitHub username:" }, { "code": { "language": "sh", "content": [ "# Fetches the izuzak's contributions", "$ ghcal -u izuzak" ] } }, { "h3": "Themes" }, { "p": "If you pass the `--light` option, then the light theme will be activated (the default theme is dark)." }, { "code": { "language": "sh", "content": [ "# jlord's contributions, light theme", "$ ghcal jlord --light" ] } }, { "h3": "No ANSI styles" }, { "p": "The `--no-ansi` option disables any colors in the output. Unicode characters, without colors will be used." }, { "code": { "language": "sh", "content": [ "# @pengywynn's contributions, but without ANSI styles", "$ ghcal pengwynn --no-ansi" ] } } ] }, "directories": { "example": "example" }, "files": [ "bin/", "app/", "lib/", "dist/", "src/", "scripts/", "resources/", "menu/", "cli.js", "index.js", "index.d.ts", "package-lock.json", "bloggify.js", "bloggify.json", "bloggify/" ] } ================================================ FILE: snap/snapcraft.yaml ================================================ name: ghcal base: core18 version: git summary: See the GitHub contributions calendar of a user in the command line description: | See the GitHub contributions calendar of a user in the command line. For example: ghcal -u ionicabizau ghcal -u ionicabizau --light ghcal -u ionicabizau --no-ansi grade: stable confinement: strict parts: ghcal: plugin: nodejs source: . apps: ghcal: command: ghcal plugs: [home, network]