-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathgitmark_friend.py
executable file
·104 lines (82 loc) · 2.61 KB
/
gitmark_friend.py
1
2
3
4
5
6
7
8
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# encoding: utf-8
"""
gitmark_add.py
Functions and classes to grab friends data from their repo
Based on gitmarks by Hilary Mason on 2010-09-24.
Copyright 2010 by Far McKon (intermediate while picking a opensource license)
"""
import json
import settings
import os
#TODO: add to settings.py (or other settings) when this is out
# of beta stage
FRIENDS_JSON = "friends.json"
class friend_scraper(object):
""" Class for scraping data from friends off of other services."""
services_json = "services.json"
services = {}
publicFriends = {}
privateFriends = {}
def __init__(self):
print "creating a service scraper to look for friends updates"
fh = open(self.services_json)
if fh:
jsonObj = fh.read()
fh.close()
del fh
self.services = json.loads(jsonObj)
def load_private_friends(self):
print "load private friends"
private_gitmarks_dir = os.path.join( settings.GITMARK_BASE_DIR, settings.PRIVATE_GITMARK_REPO_DIR)
private_friends_file = os.path.join(private_gitmarks_dir, FRIENDS_JSON)
fh = open(private_friends_file)
if fh:
jsonObj = fh.read()
fh.close()
del fh
fr = json.loads(jsonObj)
self.privateFriends.update(fr)
else:
print "ERROR: can't load friends"
return
def load_public_friends(self):
print "load public friends"
public_gitmarks_dir = os.path.join( settings.GITMARK_BASE_DIR, settings.PUBLIC_GITMARK_REPO_DIR)
public_friends_file = os.path.join(public_gitmarks_dir, FRIENDS_JSON)
fh = open(public_friends_file)
if fh:
jsonObj = fh.read()
fh.close()
del fh
fr = json.loads(jsonObj)
self.publicFriends.update(fr)
else:
print "ERROR: can't load friends"
return
def print_friends(self):
""" Debugging tool to print friend list. """
print "== public friends =="
print self.publicFriends
print "== private friends =="
print self.privateFriends
def load_friends(self):
self.load_private_friends()
self.load_public_friends()
class friend_sender_receiver(object):
""" Class for managing to send/receive message from friends.
Mostly this is for notifications of new updates from friends (or for friends)
so that their gitmarks can fetch bookmarks from your repo.
"""
if __name__ == "__main__":
print "goddammed! Do some friend stuff here"
print "THIS BETA CODE USING FILE NOT CREATED BY CONFIG"
# -- load 'friend' file
scraper = friend_scraper()
scraper.load_friends()
scraper.print_friends()
# -- sort those friends by service
#for each friend per service
# check the service for new updates
# pull or sync all the bookmarks you can
# log a datetime or info to indicate the last check