Skip to content
Newer
Older
100644 63 lines (52 sloc) 1.58 KB
4ff25f4 @mislav thor gm:check
authored
1 #!/usr/bin/env ruby
2 require 'net/http'
3 require 'curl'
4 require 'cgi'
5
6 class Gm < Thor
7 def check
8 Net::HTTP.start('userscripts.org') do |http|
9 self.class.scripts.each do |name, id|
10 req = Net::HTTP::Head.new script_path(id)
11 res = http.request(req)
12 remote_size = res.content_length
13
14 file = script_file(name)
15 local_size = File.stat(file).size
16
17 hardcoded_size = nil
18
19 File.open(file) do |script|
20 script.each do |line|
21 if line =~ /\bscriptLength = (\d+)\b/
22 hardcoded_size = $1.to_i
23 end
24 end
25 end
26
27 puts "#{name} -- remote: #{remote_size}, local: #{local_size}, hardcoded: #{hardcoded_size}"
28 end
29 end
30 end
31
32 def upload(name)
33 id = self.class.scripts[name]
34 raise ArgumentError, "cannot find script '#{name}'" unless id
35
36 print 'UserScripts.org login ("email:pass"): '
37 STDIN.gets
38 auth = $_.chomp.split(':')
39 encoded_auth = auth.map { |i| CGI::escape i }
40
41 # FIXME: this is no work! (prolly because of CSRF protection)
42 c = Curl::Easy.new("http://#{encoded_auth.join(':')}@userscripts.org/scripts/update_src/#{id}")
43 c.multipart_form_post = true
44 c.http_post(
45 Curl::PostField.content('which_source', 'file'),
46 Curl::PostField.file('file[src]', script_file(name))
47 )
48 end
49
50 def script_path(id)
51 "/scripts/source/#{id}.user.js"
52 end
53
54 def script_file(name)
55 "#{name}/#{name}.user.js"
56 end
57
58 def self.scripts
59 @@scripts ||= {
60 'endless_tweets' => 24398
61 }
62 end
63 end
Something went wrong with that request. Please try again.