aoc_cli 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +18 -2
- data/Gemfile +0 -8
- data/README.md +138 -53
- data/aoc_cli.gemspec +1 -1
- data/bin/setup +1 -2
- data/lib/aoc_cli.rb +1 -1
- data/lib/aoc_cli/commands.rb +86 -69
- data/lib/aoc_cli/database.rb +75 -14
- data/lib/aoc_cli/day.rb +58 -87
- data/lib/aoc_cli/errors.rb +18 -3
- data/lib/aoc_cli/files.rb +125 -56
- data/lib/aoc_cli/help.rb +30 -9
- data/lib/aoc_cli/interface.rb +45 -28
- data/lib/aoc_cli/paths.rb +33 -30
- data/lib/aoc_cli/solve.rb +27 -35
- data/lib/aoc_cli/tables.rb +79 -79
- data/lib/aoc_cli/tools.rb +30 -6
- data/lib/aoc_cli/version.rb +1 -3
- data/lib/aoc_cli/year.rb +49 -32
- data/sample/aoc.rc +21 -0
- metadata +4 -4
- data/pkg/aoc_cli-0.1.2.gem +0 -0
data/lib/aoc_cli/tools.rb
CHANGED
@@ -28,7 +28,7 @@ module AocCli
|
|
28
28
|
end
|
29
29
|
private
|
30
30
|
def cookie
|
31
|
-
Files::Cookie.
|
31
|
+
Files::Config::Cookie.key(user:user)
|
32
32
|
end
|
33
33
|
def url
|
34
34
|
case page.to_sym
|
@@ -75,11 +75,8 @@ module AocCli
|
|
75
75
|
end
|
76
76
|
class Get < Convert
|
77
77
|
def initialize(u:Metafile.get(:user),
|
78
|
-
y:Metafile.get(:year),
|
79
|
-
|
80
|
-
@input = Request
|
81
|
-
.new(u:u, y:y, d:d, p:p)
|
82
|
-
.get
|
78
|
+
y:Metafile.get(:year), d:nil, p:)
|
79
|
+
@input = Request.new(u:u, y:y, d:d, p:p).get
|
83
80
|
end
|
84
81
|
end
|
85
82
|
class Post < Convert
|
@@ -92,5 +89,32 @@ module AocCli
|
|
92
89
|
.post(data:data)
|
93
90
|
end
|
94
91
|
end
|
92
|
+
class Reddit
|
93
|
+
attr_reader :year, :day, :uniq, :browser
|
94
|
+
def initialize(y:Metafile.get(:year),
|
95
|
+
d:Metafile.get(:day),
|
96
|
+
b:Prefs.bool(key:"reddit_in_browser"))
|
97
|
+
@year = Validate.year(y)
|
98
|
+
@day = Validate.day(d)
|
99
|
+
@uniq = Database::Query
|
100
|
+
.new(path:Paths::Database.root("reddit"))
|
101
|
+
.select(t:"'#{year}'", where:{day:"'#{day}'"})
|
102
|
+
.flatten[1]
|
103
|
+
@browser = b
|
104
|
+
end
|
105
|
+
def open
|
106
|
+
system("#{browser ? "open" : cmd} #{link}")
|
107
|
+
end
|
108
|
+
def cmd
|
109
|
+
["ttrv", "rtv"]
|
110
|
+
.map{|cli| cli unless `which #{cli}`.empty?}
|
111
|
+
.reject{|cmd| cmd.nil?}&.first || "open"
|
112
|
+
end
|
113
|
+
def link
|
114
|
+
"https://www.reddit.com/r/"\
|
115
|
+
"adventofcode/comments/#{uniq}/"\
|
116
|
+
"#{year}_day_#{day}_solutions"
|
117
|
+
end
|
118
|
+
end
|
95
119
|
end
|
96
120
|
end
|
data/lib/aoc_cli/version.rb
CHANGED
data/lib/aoc_cli/year.rb
CHANGED
@@ -2,13 +2,13 @@ module AocCli
|
|
2
2
|
module Year
|
3
3
|
def self.refresh
|
4
4
|
puts "- Updating calendar...".blue
|
5
|
-
Year::
|
6
|
-
Year::
|
5
|
+
Year::Meta.new.write
|
6
|
+
Year::Progress.new.write
|
7
7
|
end
|
8
|
-
class
|
8
|
+
class Meta
|
9
9
|
attr_reader :user, :year, :paths
|
10
|
-
def initialize(u:
|
11
|
-
y:Metafile.get(:year)
|
10
|
+
def initialize(u:Prefs.default_alias,
|
11
|
+
y:Metafile.get(:year))
|
12
12
|
@user = Validate.user(u)
|
13
13
|
@year = Validate.year(y)
|
14
14
|
@paths = Paths::Year.new(u:user, y:year)
|
@@ -18,37 +18,32 @@ module AocCli
|
|
18
18
|
Metafile.year(u:user, y:year))
|
19
19
|
end
|
20
20
|
end
|
21
|
-
class
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@
|
27
|
-
@cal = Data::Calendar.new(u:user, y:year)
|
21
|
+
class Progress < Meta
|
22
|
+
def stats
|
23
|
+
@stats ||= Requests::Stats.new(u:user, y:year)
|
24
|
+
end
|
25
|
+
def cal
|
26
|
+
@cal ||= Requests::Calendar.new(u:user, y:year)
|
28
27
|
.fill(stars:stats.stars)
|
29
28
|
end
|
29
|
+
def file
|
30
|
+
Files::Calendar.new(stats:stats, cal:cal).make
|
31
|
+
end
|
32
|
+
def write?
|
33
|
+
Prefs.bool(key:"calendar_file")
|
34
|
+
end
|
30
35
|
def write
|
31
|
-
File.write(paths.local(f:"Stars"), file)
|
36
|
+
File.write(paths.local(f:"Stars"), file) if write?
|
32
37
|
self
|
33
38
|
end
|
34
|
-
def
|
35
|
-
|
36
|
-
stars:stats.stars
|
37
|
-
|
38
|
-
end
|
39
|
-
private
|
40
|
-
def file
|
41
|
-
text = <<~file
|
42
|
-
Year #{year}: #{stats.total_stars}/50 *
|
43
|
-
#{"-" * (cal.data[0].to_s.length + 2)}
|
44
|
-
#{cal.data.join("\n")}\n
|
45
|
-
file
|
46
|
-
text += stats.data.join("\n") if stats.total_stars > 0
|
47
|
-
text
|
39
|
+
def init_calendar_db
|
40
|
+
Database::Calendar::Init
|
41
|
+
.new(u:user, y:year, stars:stats.stars)
|
42
|
+
.insert
|
48
43
|
end
|
49
44
|
end
|
50
|
-
module
|
51
|
-
class
|
45
|
+
module Requests
|
46
|
+
class Request < Meta
|
52
47
|
attr_reader :data
|
53
48
|
def initialize(u:Metafile.get(:user),
|
54
49
|
y:Metafile.get(:year))
|
@@ -57,10 +52,11 @@ module AocCli
|
|
57
52
|
end
|
58
53
|
private
|
59
54
|
def fetch
|
60
|
-
Tools::Get.new(u:user, y:year, p:page)
|
55
|
+
Tools::Get.new(u:user, y:year, p:page)
|
56
|
+
.plain.split("\n")
|
61
57
|
end
|
62
58
|
end
|
63
|
-
class Calendar <
|
59
|
+
class Calendar < Request
|
64
60
|
def page
|
65
61
|
:Calendar
|
66
62
|
end
|
@@ -74,7 +70,7 @@ module AocCli
|
|
74
70
|
self
|
75
71
|
end
|
76
72
|
end
|
77
|
-
class Stats <
|
73
|
+
class Stats < Request
|
78
74
|
def page
|
79
75
|
:Stats
|
80
76
|
end
|
@@ -94,5 +90,26 @@ module AocCli
|
|
94
90
|
end
|
95
91
|
end
|
96
92
|
end
|
93
|
+
class GitWrap
|
94
|
+
require 'git'
|
95
|
+
attr_reader :git
|
96
|
+
def initialize
|
97
|
+
@git = Git.init
|
98
|
+
File.write(".gitignore", ignore)
|
99
|
+
git.add(".gitignore")
|
100
|
+
end
|
101
|
+
def ignore_md?
|
102
|
+
Prefs.bool(key:"ignore_md_files")
|
103
|
+
end
|
104
|
+
def ignore_meta?
|
105
|
+
Prefs.bool(key:"ignore_meta_files")
|
106
|
+
end
|
107
|
+
def ignore
|
108
|
+
<<~ignore
|
109
|
+
#{".meta\n**/.meta" if ignore_meta?}#{
|
110
|
+
"\n*.md\n**/*.md" if ignore_md?}
|
111
|
+
ignore
|
112
|
+
end
|
113
|
+
end
|
97
114
|
end
|
98
115
|
end
|
data/sample/aoc.rc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
//aoc-cli example config
|
2
|
+
//See the github repo for more information on configuring aoc-cli
|
3
|
+
//https://github.com/apexatoll/aoc-cli
|
4
|
+
|
5
|
+
[General]
|
6
|
+
//Print table in unicode rather than ascii
|
7
|
+
unicode_tables=>true
|
8
|
+
//Open Reddit in browser rather than use a Reddit CLI
|
9
|
+
reddit_in_browser=>false
|
10
|
+
|
11
|
+
[Initialise Year]
|
12
|
+
//Create a calendar file
|
13
|
+
calendar_file=>true
|
14
|
+
//Initialise git repo on year initialisation
|
15
|
+
init_git=>false
|
16
|
+
//Add calendar and puzzle files to gitignore
|
17
|
+
ignore_md_files=>true
|
18
|
+
//Add .meta files to gitignore
|
19
|
+
ignore_meta_files=>true
|
20
|
+
//Include leaderboard stats in calendar file
|
21
|
+
lb_in_calendar=>true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aoc_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Welham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: git
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -129,7 +129,7 @@ files:
|
|
129
129
|
- lib/aoc_cli/tools.rb
|
130
130
|
- lib/aoc_cli/version.rb
|
131
131
|
- lib/aoc_cli/year.rb
|
132
|
-
-
|
132
|
+
- sample/aoc.rc
|
133
133
|
homepage: https://github.com/apexatoll/aoc-cli
|
134
134
|
licenses:
|
135
135
|
- MIT
|
data/pkg/aoc_cli-0.1.2.gem
DELETED
Binary file
|