Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Makhov committed Mar 17, 2021
0 parents commit c7e4a8e
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Upload Release Asset

jobs:
build:
name: Upload Release Asset
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build project # This would actually build your project, using zip for an example artifact
run: |
zip -r ${{ github.event.repository.name }}.zip . -x ".git/*" ".github/* ${{ github.event.repository.name }}.zip"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./${{ github.event.repository.name }}.zip
asset_name: ${{ github.event.repository.name }}.zip
asset_content_type: application/zip
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# people in space

Shows number of people currently in space:

![screenshot](./screenshots/screenshot.png)

# Installation

- install [Hammerspoon](http://www.hammerspoon.org/) - a powerfull automation tool for OS X
- Manually:

Download the [latest release], and drag Hammerspoon.app from your Downloads folder to Applications.
- Homebrew:

```brew install hammerspoon --cask```

- download [gitlab-merge-requests.spoon](https://github.com/fork-my-spoons/gitlab-merge-requests.spoon/raw/master/gitlab-merge-requests.spoon.zip), unzip and double click on a .spoon file. It will be installed under `~/.hammerspoon/Spoons` folder.

- open ~/.hammerspoon/init.lua and add the following snippet, adding your parameters:

```lua
-- people in space
hs.loadSpoon('people-in-space')
spoon['people-in-space']:start()
```

This app uses icons, to properly display them, install a [feather-font](https://github.com/AT-UI/feather-font) by [downloading](https://github.com/AT-UI/feather-font/raw/master/src/fonts/feather.ttf) this .ttf font and installing it.
Binary file added icons/astronaut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/wiki.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 138 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
local obj = {}
obj.__index = obj

-- Metadata
obj.name = "people-in-space"
obj.version = "1.0"
obj.author = "Pavel Makhov"
obj.homepage = "https://github.com/fork-my-spoons/people-in-space.spoon"
obj.license = "MIT - https://opensource.org/licenses/MIT"

obj.indicator = nil
obj.timer = nil
obj.menu = {}
obj.iconPath = hs.spoons.resourcePath("icons")

local function show_warning(status, body)
hs.notify.new(function() end, {
autoWithdraw = false,
title = 'Jira Spoon',
informativeText = string.format('Received status: %s\nbody:%s', status, string.sub(body, 1, 400))
}):send()
end

local user_icon = hs.styledtext.new('', { font = {name = 'feather', size = 12 }, color = {hex = '#8e8e8e'}})
local calendar_icon = hs.styledtext.new('', { font = {name = 'feather', size = 12 }, color = {hex = '#8e8e8e'}})

local function styledText(text)
return hs.styledtext.new(text, {color = {hex = '#8e8e8e'}})
end

function split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end

local function parse_date(date_str)
local pattern = '(%d+)%-(%d+)%-(%d+)'
local y, m, d = date_str:match(pattern)
return os.time{year=y, month=m, day=d}
end

local function updateMenu()
local url = 'https://www.howmanypeopleareinspacerightnow.com/peopleinspace.json'
hs.http.asyncGet(url, {}, function(status, body)
obj.menu = {}

if status ~=200 then
show_warning(status, body)
return
end

local response = hs.json.decode(body)
obj.indicator:setTitle(response.number)

table.sort(response.people, function(left, right) return left.country < right.country end)

local cur_status = ''
local current_time = os.time(os.date('!*t'))
for _, person in ipairs(response.people) do
if cur_status ~= person.country then
table.insert(obj.menu, { title = '-'})
table.insert(obj.menu, { title = person.country, disabled = true})
cur_status = person.country
end

print()

local menu = {
image = hs.image.imageFromURL(person.biophoto):setSize({w=64,h=64}),
title = hs.styledtext.new(person.name .. '\n')
.. user_icon .. styledText(person.title .. '\n')
.. calendar_icon .. styledText(math.floor(os.difftime(current_time, parse_date(person.launchdate)) / 86400) .. ' days in space')
}

local submenu = {}

if person.bio ~= '' then
local bio = ''
for i,v in ipairs(split(person.bio, ' ')) do
bio = bio .. ' ' .. v
if i % 8 == 0 then bio = bio .. '\n' i = 0 end
end

table.insert(submenu, {
disabled = true,
title = hs.styledtext.new(bio)
})
table.insert(submenu, {title = '-'})
end

if person.twitter ~= '' then
local start, _ = string.find(person.twitter, '/[^/]*$')
local twitter_username = string.sub(person.twitter, start + 1)

table.insert(submenu, {
image = hs.image.imageFromPath(obj.iconPath .. '/twitter.png'):setSize({w=16,h=16}),
title = hs.styledtext.new(twitter_username), fn = function() os.execute('open ' .. person.twitter ) end
})
end

if person.biolink ~= '' then
table.insert(submenu, {
image = hs.image.imageFromPath(obj.iconPath .. '/wiki.png'):setSize({w=16,h=16}),
title = hs.styledtext.new('Wiki article'),
fn = function() os.execute('open ' .. person.biolink) end
})
end

menu.menu = submenu

table.insert(obj.menu, menu)
end

end)
end

function obj:buildMenu()
return obj.menu
end

function obj:init()
self.indicator = hs.menubar.new()
self.indicator:setIcon(hs.image.imageFromPath(obj.iconPath .. '/astronaut.png'):setSize({w=16,h=16}), true)
obj.indicator:setMenu(self.buildMenu)

self.timer = hs.timer.new(18000, updateMenu)
end

function obj:start()
self.timer:fire()
self.timer:start()
end


return obj
Binary file added screenshots/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c7e4a8e

Please sign in to comment.