cpsn 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mkd +42 -0
- data/Rakefile +5 -1
- data/VERSION +1 -1
- data/bin/cpsn +116 -98
- metadata +7 -5
data/README.mkd
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
cpsn
|
2
|
+
====
|
3
|
+
|
4
|
+
cpsn lets you query your friend status on the Playstation Network (tm) via the
|
5
|
+
command line interface. You can see friend status (online or offline), which
|
6
|
+
game they are playing, and, if available, the game mode and map they are
|
7
|
+
playing.
|
8
|
+
|
9
|
+
Setup
|
10
|
+
=====
|
11
|
+
|
12
|
+
Before you can use cpsn, you must first create a settings file for your PSN
|
13
|
+
username and password. Create a ~/.cpsn directory, and inside it, put a settings.yml file like:
|
14
|
+
|
15
|
+
---
|
16
|
+
:username: my_psn_username
|
17
|
+
:password: my_psn_password
|
18
|
+
|
19
|
+
That's it!
|
20
|
+
|
21
|
+
Usage
|
22
|
+
=====
|
23
|
+
|
24
|
+
'cpsn' by itself on the commandline will show you all friends on your friends
|
25
|
+
list that are online. You can optionally list one or more friend names to see
|
26
|
+
only their status, or provide a group name (see 'Defining Groups' below). You
|
27
|
+
can also pass '-o' to see your offline friends as well.
|
28
|
+
|
29
|
+
Defining Groups
|
30
|
+
===============
|
31
|
+
|
32
|
+
If you find yourself looking for the status of a few friends frequently, you can define groups of users in your settings.yml file. Groups go under the ':groups:' section in the settings.yml file, and are the name you want to call them and a list of user names.
|
33
|
+
|
34
|
+
For example:
|
35
|
+
|
36
|
+
---
|
37
|
+
:username: my_psn_username
|
38
|
+
:password: my_psn_password
|
39
|
+
|
40
|
+
:groups:
|
41
|
+
- mw2: [friend1, friend2, friend3]
|
42
|
+
|
data/Rakefile
CHANGED
@@ -6,7 +6,11 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "cpsn"
|
8
8
|
gem.summary = %Q{Query PSN friend status from the CLI}
|
9
|
-
gem.description = %Q{
|
9
|
+
gem.description = %Q{
|
10
|
+
Query PSN friend status from the CLI. Shows useful information like the
|
11
|
+
game being played, and what mode or map your friend is playing
|
12
|
+
(if available).
|
13
|
+
}
|
10
14
|
gem.email = "jbowes@repl.ca"
|
11
15
|
gem.homepage = "http://github.com/jbowes/cpsn"
|
12
16
|
gem.authors = ["James Bowes"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/bin/cpsn
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# cpsn - Query Friend status on the Playstation Network (tm)
|
4
|
+
#
|
5
|
+
# Author:: James Bowes <jbowes@repl.ca>
|
6
|
+
# Copyright:: Copyright (C) 2009 James Bowes
|
2
7
|
|
3
8
|
require 'rubygems'
|
4
9
|
require 'mechanize'
|
@@ -8,119 +13,135 @@ require 'optparse'
|
|
8
13
|
require 'logger'
|
9
14
|
require 'set'
|
10
15
|
|
11
|
-
|
16
|
+
@login_url = "https://store.playstation.com/external/index.vm?returnURL=https%3a%2f%2fsecureus.playstation.com%2fRegistration%2fPSNL%2fSignInFrame.aspx"
|
12
17
|
$friend_url = "http://profiles.us.playstation.com/playstation/psn/profile/friends"
|
13
18
|
$json_url = "http://profiles.us.playstation.com/playstation/psn/profile/get_gamer_summary_data?id="
|
14
19
|
|
15
20
|
|
16
|
-
|
17
|
-
$log.level = Logger::WARN
|
21
|
+
class Cpsn
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
attr_accessor :settings, :groups
|
24
|
+
|
25
|
+
def initialize(options)
|
26
|
+
@log = Logger.new(STDERR)
|
27
|
+
@log.level = Logger::WARN
|
28
|
+
if options[:debug]
|
29
|
+
@log.level = Logger::DEBUG
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
groups = {}
|
32
|
+
@settings = load_settings()
|
33
|
+
@groups = load_groups(@settings)
|
28
34
|
|
29
|
-
|
30
|
-
|
35
|
+
get_agent(@settings[:username].value, @settings[:password].value,
|
36
|
+
options[:cookie])
|
31
37
|
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
mem_str = ""
|
38
|
-
for user in vals.value do
|
39
|
-
members << user.value
|
40
|
-
mem_str += user.value
|
41
|
-
mem_str += " "
|
42
|
-
end
|
43
|
-
$log.debug("Found group #{name} [ #{mem_str}]")
|
44
|
-
groups[name] = members
|
39
|
+
def load_settings()
|
40
|
+
@log.debug("Loading settings")
|
41
|
+
settings = YAML::parse_file(File.expand_path("~/.cpsn/settings.yml"))
|
42
|
+
return settings
|
45
43
|
end
|
46
|
-
|
47
|
-
|
44
|
+
|
45
|
+
def load_groups(settings)
|
46
|
+
@log.debug("Loading groups")
|
47
|
+
groups = {}
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
49
|
+
if not settings[:groups]
|
50
|
+
return groups
|
51
|
+
end
|
52
|
+
|
53
|
+
for group in settings[:groups].value
|
54
|
+
name = group.value.keys[0].value
|
55
|
+
vals = group.value[group.value.keys[0]]
|
56
|
+
members = []
|
57
|
+
mem_str = ""
|
58
|
+
for user in vals.value do
|
59
|
+
members << user.value
|
60
|
+
mem_str += user.value
|
61
|
+
mem_str += " "
|
62
|
+
end
|
63
|
+
@log.debug("Found group #{name} [ #{mem_str}]")
|
64
|
+
groups[name] = members
|
65
|
+
end
|
66
|
+
return groups
|
61
67
|
end
|
62
68
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
69
|
+
def get_cookie(username, password)
|
70
|
+
@log.debug("Signing in for new cookie")
|
71
|
+
page = @agent.get(@login_url)
|
72
|
+
login_form = page.forms.first
|
73
|
+
login_form.loginName = username
|
74
|
+
login_form.password = password
|
75
|
+
page = @agent.submit(login_form)
|
76
|
+
link = page.links.first
|
77
|
+
|
78
|
+
if link.text == "Sign In"
|
79
|
+
puts "Error logging in. Did you give the right username and password?"
|
80
|
+
exit
|
81
|
+
end
|
82
|
+
|
83
|
+
page = link.click
|
84
|
+
|
85
|
+
@agent.cookie_jar.save_as File.expand_path("~/.cpsn/cookies.yml")
|
86
|
+
end
|
67
87
|
|
68
|
-
def get_agent(username, password, force_cookie)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
88
|
+
def get_agent(username, password, force_cookie)
|
89
|
+
@log.debug("Creating new user agent")
|
90
|
+
@agent = WWW::Mechanize.new
|
91
|
+
@agent.user_agent_alias = 'Mac FireFox'
|
92
|
+
@agent.redirect_ok = true
|
73
93
|
|
74
|
-
|
75
|
-
|
76
|
-
|
94
|
+
if File.exist? File.expand_path("~/.cpsn/cookies.yml") and not force_cookie
|
95
|
+
@agent.cookie_jar.load File.expand_path("~/.cpsn/cookies.yml")
|
96
|
+
else
|
97
|
+
get_cookie(username, password)
|
98
|
+
end
|
77
99
|
end
|
78
100
|
|
79
|
-
|
80
|
-
|
81
|
-
|
101
|
+
def get_friends()
|
102
|
+
@log.debug("Getting friends list")
|
103
|
+
page = @agent.get($friend_url)
|
104
|
+
divs = page.search("div.slotcontent")
|
82
105
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
106
|
+
friends = []
|
107
|
+
for div in divs
|
108
|
+
friend = div.attributes["id"]
|
109
|
+
friends << friend
|
110
|
+
@log.debug("Found friend #{friend}")
|
111
|
+
end
|
87
112
|
|
88
|
-
|
89
|
-
|
90
|
-
friend = div.attributes["id"]
|
91
|
-
friends << friend
|
92
|
-
$log.debug("Found friend #{friend}")
|
93
|
-
end
|
113
|
+
return friends
|
114
|
+
end
|
94
115
|
|
95
|
-
|
96
|
-
|
116
|
+
def get_friend_status(friend)
|
117
|
+
@log.debug("Loading friend status for #{friend}")
|
118
|
+
page = @agent.get($json_url + friend)
|
119
|
+
data = JSON.parse(page.body)
|
97
120
|
|
98
|
-
|
99
|
-
$log.debug("Loading friend status for #{friend}")
|
100
|
-
page = agent.get($json_url + friend)
|
101
|
-
data = JSON.parse(page.body)
|
121
|
+
@log.debug(data)
|
102
122
|
|
103
|
-
|
123
|
+
friend = {:name => data["userName"]}
|
104
124
|
|
105
|
-
|
125
|
+
if data["onlineStatus"] == nil
|
126
|
+
return nil
|
127
|
+
end
|
106
128
|
|
107
|
-
|
108
|
-
|
109
|
-
|
129
|
+
if data["onlineStatus"]["extensionStatus"] != nil
|
130
|
+
friend[:status] = 'online'
|
131
|
+
friend[:playing] = data["onlineStatus"]["extensionStatus"]["title"]
|
132
|
+
friend[:game_status] = data["onlineStatus"]["extensionStatus"]["status"]
|
133
|
+
else
|
134
|
+
friend[:status] = 'offline'
|
135
|
+
friend[:playing] = ""
|
136
|
+
friend[:game_status] = ""
|
137
|
+
end
|
110
138
|
|
111
|
-
|
112
|
-
friend[:status] = 'online'
|
113
|
-
friend[:playing] = data["onlineStatus"]["extensionStatus"]["title"]
|
114
|
-
friend[:game_status] = data["onlineStatus"]["extensionStatus"]["status"]
|
115
|
-
else
|
116
|
-
friend[:status] = 'offline'
|
117
|
-
friend[:playing] = ""
|
118
|
-
friend[:game_status] = ""
|
139
|
+
return friend
|
119
140
|
end
|
120
141
|
|
121
|
-
return friend
|
122
142
|
end
|
123
143
|
|
144
|
+
|
124
145
|
options = {}
|
125
146
|
optparse = OptionParser.new do |opts|
|
126
147
|
options[:offline] = false
|
@@ -128,8 +149,9 @@ optparse = OptionParser.new do |opts|
|
|
128
149
|
options[:offline] = true
|
129
150
|
end
|
130
151
|
|
152
|
+
options[:debug] = false
|
131
153
|
opts.on('-d', '--debug', 'Show debugging information') do
|
132
|
-
|
154
|
+
options[:debug] = true
|
133
155
|
end
|
134
156
|
|
135
157
|
options[:cookie] = false
|
@@ -153,29 +175,25 @@ end
|
|
153
175
|
|
154
176
|
optparse.parse!
|
155
177
|
|
156
|
-
|
157
|
-
groups = load_groups(settings)
|
158
|
-
agent = get_agent(settings[:username].value, settings[:password].value,
|
159
|
-
options[:cookie])
|
178
|
+
cpsn = Cpsn.new(options)
|
160
179
|
|
161
180
|
if ARGV.length >= 1
|
162
181
|
friend_names = Set.new []
|
163
182
|
args = ARGV[0..-1]
|
164
183
|
for arg in args
|
165
|
-
if groups.has_key? arg
|
166
|
-
friend_names.merge(groups[arg])
|
184
|
+
if cpsn.groups.has_key? arg
|
185
|
+
friend_names.merge(cpsn.groups[arg])
|
167
186
|
else
|
168
187
|
friend_names.add(arg)
|
169
188
|
end
|
170
189
|
end
|
171
190
|
else
|
172
191
|
begin
|
173
|
-
friend_names = get_friends(
|
192
|
+
friend_names = cpsn.get_friends()
|
174
193
|
rescue WWW::Mechanize::ResponseCodeError => response
|
175
|
-
puts response.response_code
|
176
194
|
if response.response_code == '403'
|
177
|
-
get_cookie(
|
178
|
-
|
195
|
+
cpsn.get_cookie(cpsn.settings[:username].value,
|
196
|
+
cpsn.settings[:password].value)
|
179
197
|
retry
|
180
198
|
end
|
181
199
|
end
|
@@ -183,11 +201,11 @@ end
|
|
183
201
|
|
184
202
|
for friend_name in friend_names
|
185
203
|
begin
|
186
|
-
friend = get_friend_status(
|
204
|
+
friend = cpsn.get_friend_status(friend_name)
|
187
205
|
rescue WWW::Mechanize::ResponseCodeError => response
|
188
206
|
if response.response_code == '403'
|
189
|
-
get_cookie(
|
190
|
-
|
207
|
+
cpsn.get_cookie(cpsn.settings[:username].value,
|
208
|
+
cpsn.settings[:password].value)
|
191
209
|
retry
|
192
210
|
end
|
193
211
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cpsn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Bowes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-22 00:00:00 -05:00
|
13
13
|
default_executable: cpsn
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,16 +32,18 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.1.7
|
34
34
|
version:
|
35
|
-
description: Query PSN friend status from the CLI
|
35
|
+
description: "\n Query PSN friend status from the CLI. Shows useful information like the\n game being played, and what mode or map your friend is playing\n (if available).\n "
|
36
36
|
email: jbowes@repl.ca
|
37
37
|
executables:
|
38
38
|
- cpsn
|
39
39
|
extensions: []
|
40
40
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.mkd
|
43
|
+
- TODO
|
43
44
|
files:
|
44
45
|
- .gitignore
|
46
|
+
- README.mkd
|
45
47
|
- Rakefile
|
46
48
|
- TODO
|
47
49
|
- VERSION
|