cpsn 0.0.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.
Files changed (5) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +22 -0
  3. data/VERSION +1 -0
  4. data/cpsn +87 -0
  5. metadata +87 -0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.sw?
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "cpsn"
8
+ gem.summary = %Q{Query PSN friend status from the CLI}
9
+ gem.description = %Q{Query PSN friend status from the CLI}
10
+ gem.email = "jbowes@repl.ca"
11
+ gem.homepage = "http://github.com/jbowes/cpsn"
12
+ gem.authors = ["James Bowes"]
13
+ gem.add_dependency "mechanize"
14
+ gem.add_dependency "hpricot"
15
+ gem.add_dependency "json"
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ task :default => nil
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/cpsn ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'mechanize'
5
+ require 'hpricot'
6
+ require 'json'
7
+
8
+ $username = ARGV[0]
9
+ $password = ARGV[1]
10
+
11
+ $login_url = "https://store.playstation.com/external/index.vm?returnURL=https%3a%2f%2fsecureus.playstation.com%2fRegistration%2fPSNL%2fSignInFrame.aspx"
12
+ $friend_url = "http://profiles.us.playstation.com/playstation/psn/profile/friends"
13
+ $json_url = "http://profiles.us.playstation.com/playstation/psn/profile/get_gamer_summary_data?id="
14
+
15
+ def get_agent()
16
+ agent = WWW::Mechanize.new
17
+ agent.user_agent_alias = 'Mac FireFox'
18
+ agent.redirect_ok = true
19
+
20
+ page = agent.get($login_url)
21
+ login_form = page.forms.first
22
+ login_form.loginName = $username
23
+ login_form.password = $password
24
+ page = agent.submit(login_form)
25
+ link = page.links.first
26
+
27
+ if link.text == "Sign In"
28
+ puts "Error logging in. Did you give the right username and password?"
29
+ exit
30
+ end
31
+
32
+ page = link.click
33
+
34
+ return agent
35
+ end
36
+
37
+ def get_friends(agent)
38
+ page = agent.get($friend_url)
39
+ body = Hpricot.parse(page.body)
40
+ divs = body.search("div.slotcontent")
41
+
42
+ friends = []
43
+ for div in divs
44
+ friends << div.attributes["id"]
45
+ end
46
+
47
+ return friends
48
+ end
49
+
50
+ def get_friend_status(agent, friend)
51
+ page = agent.get($json_url + friend)
52
+ data = JSON.parse(page.body)
53
+
54
+ friend = {:name => data["userName"]}
55
+
56
+ if data["onlineStatus"] == nil
57
+ return nil
58
+ end
59
+
60
+ if data["onlineStatus"]["extensionStatus"] != nil
61
+ friend[:status] = 'online'
62
+ friend[:playing] = data["onlineStatus"]["extensionStatus"]["title"]
63
+ else
64
+ friend[:status] = 'offline'
65
+ friend[:playing] = ""
66
+ end
67
+
68
+ return friend
69
+ end
70
+
71
+ agent = get_agent()
72
+
73
+ if ARGV.length >= 3
74
+ friend_names = ARGV[2..-1]
75
+ else
76
+ friend_names = get_friends(agent)
77
+ end
78
+
79
+ for friend_name in friend_names
80
+ friend = get_friend_status(agent, friend_name)
81
+
82
+ if friend
83
+ puts friend[:status] + "\t" + friend[:name] + "\t" + friend[:playing]
84
+ else
85
+ puts "Error: no access to " + friend_name
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cpsn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - James Bowes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-31 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mechanize
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hpricot
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Query PSN friend status from the CLI
46
+ email: jbowes@repl.ca
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - .gitignore
55
+ - Rakefile
56
+ - VERSION
57
+ - cpsn
58
+ has_rdoc: true
59
+ homepage: http://github.com/jbowes/cpsn
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Query PSN friend status from the CLI
86
+ test_files: []
87
+