lipaste 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +26 -0
- data/bin/lipaste +8 -0
- data/lib/lipaste/cli.rb +57 -0
- data/lib/lipaste/config.rb +45 -0
- data/lib/lipaste/files.rb +26 -0
- data/lib/lipaste/lichess.rb +45 -0
- data/lib/lipaste/version.rb +3 -0
- data/lib/lipaste.rb +1 -0
- data/lipaste.gemspec +24 -0
- metadata +85 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 61ed0cca94d631a0f21731d047be8bbf209d2085
|
|
4
|
+
data.tar.gz: d5189757ab90dac8ff58203de63e90d15fa93734
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9921d6814455fea9a3b8ce354cbc3c32a51a3664c560352cf7497e34449a7d1a5bd4cfab23d392db7dd3dc279c02ed709a1fb9cb762f452834f91945b9902df0
|
|
7
|
+
data.tar.gz: ff7438755758ce4208a4d43604ff80483ac8030595966da295da1c2268196484a062384c12eb3c5fd247d06bb117c8f11a5ac2ddd4c8cbb5bd9d1566d0a09b21
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Evan Solomon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Lipaste
|
|
2
|
+
|
|
3
|
+
Little command line tool to upload chess games in PGN format to the Lichess analyzer.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
gem install lipaste
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
# Optionally login to save uploaded games to your Lichess account
|
|
15
|
+
# You only need to do this once
|
|
16
|
+
lipaste login
|
|
17
|
+
|
|
18
|
+
# Upload the newest .pgn file from ~/Downloads
|
|
19
|
+
lipaste
|
|
20
|
+
|
|
21
|
+
# Upload a specific PGN file
|
|
22
|
+
lipaste -p /path/to/game.pgn
|
|
23
|
+
|
|
24
|
+
# Delete saved credentials if any exist
|
|
25
|
+
lipaste logout
|
|
26
|
+
```
|
data/bin/lipaste
ADDED
data/lib/lipaste/cli.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "thor"
|
|
2
|
+
|
|
3
|
+
require "lipaste/config"
|
|
4
|
+
require "lipaste/files"
|
|
5
|
+
require "lipaste/lichess"
|
|
6
|
+
|
|
7
|
+
module Lipaste
|
|
8
|
+
class CLI < Thor
|
|
9
|
+
desc "upload", "Upload a PGN."
|
|
10
|
+
method_option :pgn,
|
|
11
|
+
:aliases => "-p",
|
|
12
|
+
:type => :string,
|
|
13
|
+
:desc => "Specify a PGN file or string to upload."
|
|
14
|
+
def upload
|
|
15
|
+
conf = Lipaste::Config.read
|
|
16
|
+
unless conf == nil
|
|
17
|
+
begin
|
|
18
|
+
cookie = Lipaste::Lichess.login conf[:username], conf[:password]
|
|
19
|
+
rescue
|
|
20
|
+
STDERR.puts "Error logging in to Lichess"
|
|
21
|
+
exit 1
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if options.pgn == nil
|
|
26
|
+
# Use a file from ~/Downloads by default
|
|
27
|
+
pgn = File.read Lipaste::Files.get_latest_downloaded_pgn
|
|
28
|
+
elsif File.exists? options.pgn
|
|
29
|
+
# Read the file if a path is provided
|
|
30
|
+
pgn = File.read options.pgn
|
|
31
|
+
else
|
|
32
|
+
# Treat any other argument as a PGN string
|
|
33
|
+
STDERR.puts "Invalid PGN file: #{options.pgn}"
|
|
34
|
+
exit 1
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
puts Lipaste::Lichess.upload cookie, pgn
|
|
38
|
+
end
|
|
39
|
+
default_task :upload
|
|
40
|
+
|
|
41
|
+
desc "login", "Setup your Lichess username and password."
|
|
42
|
+
def login
|
|
43
|
+
Lipaste::Config.create_config
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc "logout", "Remove any saved Lichess username and password."
|
|
47
|
+
def logout
|
|
48
|
+
Lipaste::Config.destroy
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
desc "version", "Show version."
|
|
52
|
+
map %w(-v --version) => :version
|
|
53
|
+
def version
|
|
54
|
+
say Lipaste::VERSION
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
3
|
+
module Lipaste
|
|
4
|
+
class Config
|
|
5
|
+
FILE_NAME = ".lipaste"
|
|
6
|
+
|
|
7
|
+
def self.read
|
|
8
|
+
return nil unless exists?
|
|
9
|
+
|
|
10
|
+
content = File.read get_path
|
|
11
|
+
YAML.load content
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.get_path
|
|
15
|
+
home = File.expand_path "~"
|
|
16
|
+
File.join home, FILE_NAME
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.exists?
|
|
20
|
+
File.exists? get_path
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.destroy
|
|
24
|
+
File.delete get_path if exists?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.create_config
|
|
28
|
+
puts "Your credentials will only be stored locally on your computer."
|
|
29
|
+
print "Username: "
|
|
30
|
+
username = $stdin.gets.chomp
|
|
31
|
+
|
|
32
|
+
print "Password (text will be hidden): "
|
|
33
|
+
`stty -echo`
|
|
34
|
+
password = $stdin.gets.chomp
|
|
35
|
+
`stty echo`
|
|
36
|
+
|
|
37
|
+
_create_config username, password
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self._create_config(username, password)
|
|
41
|
+
data = {username: username, password: password}
|
|
42
|
+
File.write get_path, data.to_yaml
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Lipaste
|
|
2
|
+
class Files
|
|
3
|
+
def self.get_latest_downloaded_pgn
|
|
4
|
+
downloads = get_downloads_dir
|
|
5
|
+
pgns = list_pgn_files downloads
|
|
6
|
+
get_latest_file pgns
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.get_downloads_dir
|
|
10
|
+
home = File.expand_path "~"
|
|
11
|
+
File.join home, "Downloads"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.list_pgn_files(dir)
|
|
15
|
+
glob = File.join dir, "*"
|
|
16
|
+
Dir.glob(glob).select {|f| f =~ /\.pgn$/}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.get_latest_file(files)
|
|
20
|
+
mtimes = files.map {|f| {name: f, mtime: File.mtime(f)}}
|
|
21
|
+
mtimes.sort! {|a, b| a[:mtime] - b[:mtime]}
|
|
22
|
+
file = mtimes.pop
|
|
23
|
+
file[:name]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require "net/http"
|
|
2
|
+
require "uri"
|
|
3
|
+
|
|
4
|
+
module Lipaste
|
|
5
|
+
class Lichess
|
|
6
|
+
HOST = "http://en.lichess.org"
|
|
7
|
+
LOGIN_COOKIE_NAME = "lila2"
|
|
8
|
+
|
|
9
|
+
def self.login(username, password)
|
|
10
|
+
uri = get_uri "login"
|
|
11
|
+
res = Net::HTTP.post_form uri, username: username, password: password
|
|
12
|
+
cookie_headers = res.get_fields "set-cookie"
|
|
13
|
+
matches = cookie_headers.map {|c| c.match /^([^=]+)=([^;]+)/}
|
|
14
|
+
cookies = matches.map {|match| {name: match[1], value: match[2]}}
|
|
15
|
+
login_cookie = cookies.select {|cookie| cookie[:name] == LOGIN_COOKIE_NAME}
|
|
16
|
+
login_cookie.pop[:value]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.upload(login_cookie, pgn)
|
|
20
|
+
uri = get_uri "import"
|
|
21
|
+
http = Net::HTTP.new uri.host
|
|
22
|
+
request = Net::HTTP::Post.new uri.request_uri
|
|
23
|
+
request.set_form_data pgn: pgn
|
|
24
|
+
request["Cookie"] = "#{LOGIN_COOKIE_NAME}=#{login_cookie}" if login_cookie
|
|
25
|
+
response = http.request request
|
|
26
|
+
|
|
27
|
+
if response.code == "429"
|
|
28
|
+
STDERR.puts "Your account is currently rated limited by Lichess, try waiting a couple minutes"
|
|
29
|
+
exit 1
|
|
30
|
+
elsif response.code != "303"
|
|
31
|
+
STDERR.puts "Error uploading to Lichess"
|
|
32
|
+
STDERR.puts response.code
|
|
33
|
+
STDERR.puts response.body
|
|
34
|
+
exit 1
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
paste_route = response.to_hash["location"][0]
|
|
38
|
+
return get_uri(paste_route).to_s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.get_uri(route)
|
|
42
|
+
URI.parse "#{HOST}/#{route.sub(/^\//, "")}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/lipaste.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "lipaste/cli"
|
data/lipaste.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "lipaste/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "lipaste"
|
|
8
|
+
spec.version = Lipaste::VERSION
|
|
9
|
+
spec.authors = ["Evan Solomon"]
|
|
10
|
+
spec.email = ["evan@evanalyze.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Upload PGN files to Lichess analysis service.}
|
|
13
|
+
spec.description = %q{Upload PGN from files or strings to Lichess via the CLI.}
|
|
14
|
+
spec.homepage = "https://github.com/evansolomon/lipaste"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = "bin"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
|
23
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
|
24
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lipaste
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Evan Solomon
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-06-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.9'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.9'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: thor
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.19.1
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.19.1
|
|
41
|
+
description: Upload PGN from files or strings to Lichess via the CLI.
|
|
42
|
+
email:
|
|
43
|
+
- evan@evanalyze.com
|
|
44
|
+
executables:
|
|
45
|
+
- lipaste
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- Gemfile
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- bin/lipaste
|
|
54
|
+
- lib/lipaste.rb
|
|
55
|
+
- lib/lipaste/cli.rb
|
|
56
|
+
- lib/lipaste/config.rb
|
|
57
|
+
- lib/lipaste/files.rb
|
|
58
|
+
- lib/lipaste/lichess.rb
|
|
59
|
+
- lib/lipaste/version.rb
|
|
60
|
+
- lipaste.gemspec
|
|
61
|
+
homepage: https://github.com/evansolomon/lipaste
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata: {}
|
|
65
|
+
post_install_message:
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 2.4.7
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 4
|
|
84
|
+
summary: Upload PGN files to Lichess analysis service.
|
|
85
|
+
test_files: []
|