Class: AtcoderGreedy::Command
- Inherits:
-
Thor
- Object
- Thor
- AtcoderGreedy::Command
- Defined in:
- lib/atcoder_greedy/command.rb,
lib/atcoder_greedy/command/test.rb,
lib/atcoder_greedy/command/config.rb,
lib/atcoder_greedy/command/create.rb,
lib/atcoder_greedy/command/submit.rb,
lib/atcoder_greedy/command/destroy.rb,
lib/atcoder_greedy/command/template.rb
Instance Method Summary collapse
- #config ⇒ Object
- #create(contest_url) ⇒ Object
- #destroy(contest_name) ⇒ Object
-
#submit(submit_file) ⇒ Object
TODO: 提出言語のオプション.
- #template ⇒ Object
- #test(problem_name) ⇒ Object
Instance Method Details
#config ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/atcoder_greedy/command/config.rb', line 9 def config languages = Languages::ALL_LANGUAGES config_path = Dir.home + '/.atcoder_greedy' if Dir.exists?(config_path) puts "Your current user_id is #{AtcoderGreedy.config[:user_id]} and current language is [#{AtcoderGreedy.config[:language]}]." else Dir.mkdir(config_path) yml_path = AtcoderGreedy.get_config_path + '/settings.yml' File.open(yml_path, 'w').close end # user setting agent = Mechanize.new loop do print 'Input your user_id: ' user_id = $stdin.gets.chomp! print 'Input your password: ' password = $stdin.gets.chomp! break if user_id.size == 0 || password.size == 0 print 'Doing test login ...' response = nil agent.get('http://abc032.contest.atcoder.jp/login') do |page| response = page.form_with(action: '/login') do |f| f.field_with(name: 'name').value = user_id f.field_with(name: 'password').value = password end.submit end if response.response['x-imojudge-simpleauth'] == 'Passed' puts 'OK!' AtcoderGreedy.configure(user_id: user_id) AtcoderGreedy.configure(password: password) break else puts 'Failed! Confirm input and try again.' end end # language setting puts "Choose default language from: #{languages}" print "Input languages: " loop do s = $stdin.gets.chomp! if languages.include?(s) AtcoderGreedy.configure(language: s) puts "Update Your default language to [#{AtcoderGreedy.config[:language]}]." break elsif s.size == 0 break else puts "Invalid language. please try again:" end end end |
#create(contest_url) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/atcoder_greedy/command/create.rb', line 15 def create(contest_url) = { no: {input: false, template: false}, problems: [], directory: [:select_directory], language: [:select_language], template: [:select_template] } [:no][:input] = true if [:no_input] [:no][:template] = true if [:no_templates] [:problems] = [:select_problem].split unless [:select_problem].nil? contest = Contest.new(contest_url, ) # TODO: contest_infoが存在したときの処理 File.open("#{contest.dir}/.contest_info.yml", 'w') do |f| info = { name: contest.name, url: contest.url, task: {} } contest.problems.each do |p| info[:task][:"#{p[:name]}"] = { id: p[:task_id] } end f.puts info.to_yaml end end |
#destroy(contest_name) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/atcoder_greedy/command/destroy.rb', line 8 def destroy(contest_name) puts "Destroy ./#{contest_name} [y/n]?" s = $stdin.gets if s == 'y' || s == 'yes' if system("rm -r ./#{contest_name}") puts 'deleted.' else raise 'Runtime Error' end end end |
#submit(submit_file) ⇒ Object
TODO: 提出言語のオプション
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/atcoder_greedy/command/submit.rb', line 23 def submit(submit_file) print "Submit [#{submit_file}] ... " contest_info = YAML.load_file("./.contest_info.yml") problem = File.basename(submit_file, '.*') if contest_info[:task].include?(:"#{problem}") task_id = contest_info[:task][:"#{problem}"][:id] else raise "Unknown problem: #{problem}" end atcoder = Atcoder.new atcoder.login(contest_info[:url]) submit_url = contest_info[:url] + "/submit?task_id=#{task_id}" atcoder.agent.get(submit_url) do |page| p = page.form_with(action: "/submit?task_id=#{task_id}") do |f| f.field_with(name: 'source_code').value = File.open(submit_file).read f.field_with(name: 'task_id').value = task_id f.field_with(name: "language_id_#{task_id}").value = get_language_id(File.extname(submit_file)) end.submit puts 'Done!' Launchy.open p.uri end end |
#template ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/atcoder_greedy/command/template.rb', line 12 def template temp = GreedyTemplate.new if [:add] temp.add([:add]) elsif [:list] temp.list elsif [:set_default] temp.set_default([:set_default]) elsif [:delete] temp.delete([:delete]) end end |