Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated overview with code layout info

Removed friends.json to put it into private/public bookmarks system
Updated config.py
Removed main gitmark object from gitmark_add.py and moved it to getmark.py
Added "we use HTTPS" note to delicious_import.py help
Started basic code for gitmark_friend usage.
Started services.json file for services we know how to use
  • Loading branch information...
commit a01841e7d1901f74f45a857e465ca8ac0d8765aa 1 parent 40a734a
Far McKon authored
20 OVERVIEW
View
@@ -67,4 +67,24 @@ Brass: Filesystem:
/posted - encrypted bookmarks 'sent' from friends (public key if to/from other users)
- /content - (optional) local content (scraped pages, stats, info, tags info, etc) (can be synced to git repo type C)
+
+=====
+Python Code Layout
+=====
+
+The main classes and code are as follows:
+
+ gitmark.py
+ - class gitmark:
+ Class represents a single gitmark and it's stats and metadata.
+ - class gitmarkRepoSyncer:
+ Calss contains tools for managing remote <-> local repositories
+ Most of this is automated into a simple 'fetch, merge, check for changes, push'
+
+ gitmark_add.py
+ No class, this is a command line file to add gitmarks to the repository.
+
+ gitmark_friend.py
+ No class, this is a command line file to check for friends updates.
+
5 config.py
View
@@ -20,6 +20,11 @@
USE_SHELL = os.name == 'nt'
def configure_gitmarks():
+ """
+ This funcion does the basic configuration of gitmarks. It tries to download
+ needed software, get settings from users, and spawns the basic on-disk files for
+ the bookmarks.
+ """
# -- pull needed libraries from the net
download_needed_software()
4 delicious_import.py 100644 → 100755
View
@@ -112,7 +112,7 @@ def import_delicious_to_local_git(username, password='', url=None):
addToRepo(newMarksList[0],doPush=False)
# -- hack test main for when yahoo sucks and I need to test
-if __name__ == '__fmain__':
+if __name__ == '__offfline_main__':
x = { "extended": "",
@@ -147,7 +147,7 @@ def import_delicious_to_local_git(username, password='', url=None):
if __name__ == '__main__':
- usage = "Usage: python delicious_import.py cached-page-uri\nOR\nUsage: python delicious_import.py username password"
+ usage = "Usage: python delicious_import.py cached-page-uri\nOR\nUsage: python delicious_import.py username password\n***Password and username are sent as HHTTPS***"
if( len(sys.argv) == 2):
import getpass
0  friends.json
View
No changes.
370 gitmark.py
View
@@ -0,0 +1,370 @@
+"""
+File contains the gitmarks object clas.
+"""
Far McKon Owner

goddamm this stinks (test comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+import sys, os
+import urllib, httplib
+import re
+import csv
+import subprocess
+import time
+from optparse import OptionParser
+import json
+import hashlib
+# -- Our own gitmarks settings
+import settings
+
+#our version of gitmarks
+GITMARK_VER_STRING = 'gitmark.0.2'
+
+# Arguments are passed directly to git, not through the shell, to avoid the
+# need for shell escaping. On Windows, however, commands need to go through the
+# shell for git to be found on the PATH, but escaping is automatic there. So
+# send git commands through the shell on Windows, and directly everywhere else.
+USE_SHELL = os.name == 'nt'
+
+
+class gitmark(object):
+
+ # -- GitMarks members
+ # If you add member variables you don't want in a gitmark, delete them in JOSNBlock below
+ # Otherwise self.__dict__ works rong.
+ uri = None #string
+ hash = None #hash value
+ summary = None #string
+ description = None #string
+ tags = [] #list of strings of tags
+ time = None #ISO8601 absolute date time
+ creator = None
+ rights = None #creative commons rights string
+ tri = [] #transitionary resource locator. IRL bit.ly, goo.gl, etc
+ content = '' #content of the site. Lazyloads and should do smart local/away fetch
+ title = None
+ extended = None
+ meta = None
+ private = None
+ ver = GITMARK_VER_STRING
+
+ def __init__(self,uri, creator=None, dictValues=None):
+ # -- temp. Force build deafults before overriding
+ self.uri = uri
+ self.hash = self.generateHash(uri)
+ self.time = time.strftime("%Y-%m-%dT%H:%M:%SZ")
+ self.creator = creator
+ self.rights = 'CC BY'
+ self.private = True #default to private for safety
+
+ if dictValues:
+ #DANGER: this is a security danger
+ self.__dict__
+ #TODO: Do I want to return self?
+
+
+ def addTags(self, stringList):
+ #if we have more than 1 quote, split by quotes
+ if(stringList.count('"') > 1):
+ print 'has qouted string! We fail'
+ else :
+ list = stringList.split(',')
+ list = [ l.lstrip().rstrip() for l in list]
+ #TODO: do some smart string hacking, for different strings
+ # of data formatting
+ self.tags.extend(list)
+
+ def noContentSet(self):
+ """
+ returns true of this gitmark is set to 'get no content'
+ """
+ #TODO menoize this result, and kill the menoize if we get
+ # a change to the tag. Maybe menoize to a hash of the list,
+ # and if the hash changes, re-calculate?
+ if 'no content' in self.tags:
+ return True
+ elif 'no_content' in self.tags:
+ return True
+ return False
+
+ def __str__(self):
+ return '<gitmark obj for "%s" by "%s"\n>' %(self.uri, self.creator)
+
+ def setPrivacy(self, privacy):
+ """ Set this gitmark to be private """
+ self.private = privacy
+
+ def generateHash(self, uri = None):
+ """generates a hash for our URI (or the passed
+ URI if it is not null"""
+ if(uri == None):
+ uri = self.uri
+ m = hashlib.md5()
+ m.update(uri)
+ return m.hexdigest()
+
+ def parseTitle(self, content=None):
+ """ parses the tile from html content, sets it to
+ our local title value, and returns the title to the caller"""
+ if(content == None):
+ content = self.content
+ self.title = self.cls_parseTitle(content)
+ return self.title
+
+ def getContent(self, uri=None):
+ """
+ Get content from the web, and store it to our local
+ content structure. IF we have a uri, gets contents from
+ there instead of our local uri.
+ """
+ if( uri == None):
+ uri = self.uri
+ #FUTURE: do we want to allow a different URI to get passed in?
+ self.content = self.cls_getContent(uri)
+
+ def uncacheContent(self, target_file):
+ """
+ Reads content from our local cache if we have it,
+ otherwise it will fetch that content from the web (not
+ store it) and save it to the local gitmark.
+ """
+ if os.path.isfile(target_file) :
+ fh = open(target_file,"r")
+ self.content = fh.read()
+ del fh
+ else:
+ print >>sys.stderr, ("Warning: no local content for this gitmark."
+ "tryig to read from web")
+ self.getContent()
+
+ def setTimeIfEmpty(self):
+ if self.time == None :
+ self.time = time.strftime("%Y-%m-%dT%H:%M:%SZ")
+
+ def cacheContent(self, target_file, content=None):
+ """
+ Write this gitmarks content to the target file. If this
+ content is specified, then that content is written instead
+ of the content in this gitmark
+ """
+ # -- lazily git store any existing file if necessary
+ if os.path.isfile(target_file) :
+ #check the md5 sum of the contet of this file,
+ #if it does NOT match our new content, then
+ print "do magic here to md5 sum, and cache file if needed"
+ if content == None:
+ content = self.content
+ self.cls_saveContent(target_file, content)
+
+ def addMyselfLocally(self, localGitmarkDir, localTagsDir):
+ """
+ This method causes a gitmark to
+ add itself to the local repository.
+ """
+ print "not used. old code. Use for reference only"
+ exit(-5)
+
+ print "adding myself to the local repository"
+ if(self.private != False):
+ print "this is a private mark. Encrypting not yet enabled. Do not store"
+ else :
+ # -- write gitmark
+ fname = os.path.join(localGitmarkDir,self.hash)
+ #fp = open(fname,"w")
+ print 'debug fwrite of file "%s"' % fp
+ print '---'
+ print self.JSONBlock()
+ print '---'
+ #fwrite(self.JOSNBlock())
+ #fclose(fp)
+ # add git add here
+
+ # -- write tags
+ fname = os.path.join(localGitmarkDir,self.hash)
+ fp = open(fname,"w")
+ prettyTags = self.prettyTags()
+ uglyTags = self.uglyTags()
+ tags = set(uglyTags.append(prettyTags))
+ for tag in tags:
+ fname = os.path.join(localGitmarkDir,self.hash)
+ print 'tag filename "%s" ' %fname
+ # add git add here
+ settings.TAG_SUB_PATH
+
+
+
+ def JOSNBlock(self):

Shouldn't this be JSONBlock(self):

And in associated usage.

Far McKon Owner
FarMcKon added a note

Yup, that is a type. I looked at the 3 times before I even saw the typo. Staring at code too long I guess. Good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ """creates and retuns a JSON text block of
+ current members of this gitMark. """
+ d = self.__dict__
+ if 'content' in d.keys() :
+ del d['content'] #remove content, we don't want that
+ return json.dumps(d,indent=4)
+
+ def miniJSONBlock(self):
+ """ creates and returns a minimun json block, used for tag files """
+ d = {'hash':self.hash, 'title':self.title, 'uri':self.uri,
+ 'creator':self.creator, 'ver':self.ver }
+ return json.dumps(d,indent=4)
+
+
+ def prettyTags(self):
+ """ tags, cleaned from delicious and make nicer looking"""
+ g = []
+ for t in self.tags:
+ print t
+ if '_' in t:
+ g.append(t.replace('_',' '))
+ else:
+ g.append(t)
+ print g
+ return g
+
+ def uglyTags(self):
+ """ tags as gotten raw, un-prettied for search and use"""
+ return self.tags
+
+
+ def everyPossibleTagList(self):
+ allTags = self.prettyTags()
+ allTags.extend(self.uglyTags())
+ allTags = set(allTags)
+ return allTags
+
+ @classmethod
+ def cls_hydrate(cls, filename):
+ """
+ Create a gitmark object from files on the local filesystem.
+ """
+ f = open(filename,'r')
+ if(f):
+ jsonObj = f.read()
+ f.close()
+ del f
+ obj = json.loads(jsonObj)
+ print obj
+ mark = gitmark(settings.USER_NAME)
+ print "INCOMPLETE FUNCTION cls_hydrate"
+ else:
+ print "failed to read/load %s" %filename
+ return None
+
+ @classmethod
+ def cls_saveContent(cls, filename, content):
+ """
+ """
+ f = open(filename, 'w')
+ f.write(content)
+ f.close()
+ return filename
+
+ @classmethod
+ def cls_generateHash(cls, text):
+ m = hashlib.md5()
+ m.update(text)
+ return m.hexdigest()
+
+ @classmethod
+ def cls_getContent(cls, url):
+ try:
+ h = urllib.urlopen(url)
+ content = h.read()
+ h.close()
+ h = urllib.urlopen(url)
+ except IOError, e:
+ print >>sys.stderr, ("Error: could not retrieve the content of a"
+ " URL. The bookmark will be saved, but its content won't be"
+ " searchable. URL: <%s>. Error: %s" % (url, e))
+ content = ''
+ except httplib.InvalidURL, e: #case: a redirect is giving me www.idealist.org:, which causes a fail during port-number search due to trailing :
+ print >>sys.stderr, ("Error: url or url redirect contained an"
+ "invalid URL. The bookmark will be saved, but its content"
+ "won't be searchable. URL: <%s>. Error: %s" % (url, e))
+ content=''
+ return content
+
+ @classmethod
+ def cls_parseTitle(cls, content):
+ re_htmltitle = re.compile(".*<title>(.*)</title>.*")
+ t = re_htmltitle.search(content)
+ try:
+ title = t.group(1)
+ except AttributeError:
+ title = '[No Title]'
+ return title
+
+ @classmethod
+ def gitAdd(cls, files, forceDateTime=None, gitBaseDir=None):
+ """ add this git object's files to the local repository"""
+ # TRICKY:Set the authoring date of the commit based on the imported timestamp. git reads the GIT_AUTHOR_DATE environment var.
+ # TRICKTY: sets the environment over to the base directory of the gitmarks base
+ cwd_dir = os.path.abspath(os.getcwd())
+
+ if gitBaseDir: os.chdir(os.path.abspath(gitBaseDir))
+ if forceDateTime : os.environ['GIT_AUTHOR_DATE'] = forceDateTime
+ subprocess.call(['git', 'add'] + files, shell=USE_SHELL)
+ if forceDateTime : del os.environ['GIT_AUTHOR_DATE']
+ if gitBaseDir: os.chdir(cwd_dir)
+
+ @classmethod
+ def gitCommit(cls, msg, gitBaseDir = None):
+ """ commit the local repository to the server"""
+ # TRICKTY: sets the environment over to the base directory of the gitmarks base
+ cwd_dir = os.path.abspath(os.getcwd())
+ if gitBaseDir: os.chdir(os.path.abspath(gitBaseDir))
+ subprocess.call(['git', 'commit', '-m', msg], shell=USE_SHELL)
+ if gitBaseDir: os.chdir(cwd_dir)
+
+ @classmethod
+ def gitPush(cls, gitBaseDir = None):
+ """ push the local origin to the master"""
+ # TRICKTY: sets the environment over to the base directory of the gitmarks base
+ cwd_dir = os.path.abspath(os.getcwd())
+ if gitBaseDir: os.chdir(os.path.abspath(gitBaseDir))
+ print os.getcwd()
+ pipe = subprocess.Popen("git push origin master", shell=True) #Tricky: shell must be true
+ pipe.wait()
+ if gitBaseDir: os.chdir(cwd_dir)
+
+
+# @classmethod
+# def saveTagData(cls, tag, url, title, base_filename):
+# tag_filename = os.path.join(TAG_PATH, tag)
+# tag_writer = csv.writer(open(tag_filename, 'a'))
+# tag_writer.writerow([url, title, base_filename])
+# return tag_filename
+#
+# @classmethod
+# def parseTitle(cls, content):
+# re_htmltitle = re.compile(".*<title>(.*)</title>.*")
+# t = re_htmltitle.search(content)
+# try:
+# title = t.group(1)
+# except AttributeError:
+# title = '[No Title]'
+#
+# return title
+#
+# @classmethod
+# def getContent(cls, url):
+# try:
+# h = urllib.urlopen(url)
+# content = h.read()
+# h.close()
+# h = urllib.urlopen(url)
+# except IOError, e:
+# print >>sys.stderr, ("Error: could not retrieve the content of a"
+# " URL. The bookmark will be saved, but its content won't be"
+# " searchable. URL: <%s>. Error: %s" % (url, e))
+# content = ''
+# except httplib.InvalidURL, e: #case: a redirect is giving me www.idealist.org:, which causes a fail during port-number search due to trailing :
+# print >>sys.stderr, ("Error: url or url redirect contained an"
+# "invalid URL. The bookmark will be saved, but its content"
+# "won't be searchable. URL: <%s>. Error: %s" % (url, e))
+# content=''
+# return content
+
+
+class gitmarkRepoManager(object):
+
+ def __init__(self):
+ print "initalizing a repo manager"
+
+
353 gitmark_add.py
View
@@ -12,21 +12,16 @@
import sys, os
import urllib, httplib
import re
-import hashlib
import csv
import subprocess
import time
from optparse import OptionParser
import json
+# -- Our own gitmarks settings
import settings
+from gitmark import gitmark
+from gitmark import USE_SHELL
-# Arguments are passed directly to git, not through the shell, to avoid the
-# need for shell escaping. On Windows, however, commands need to go through the
-# shell for git to be found on the PATH, but escaping is automatic there. So
-# send git commands through the shell on Windows, and directly everywhere else.
-USE_SHELL = os.name == 'nt'
-
-GITMARK_VER_STRING = 'gitmark.alpha.1'
def canHazWebs():
""" Returns true/false if I can't ping google,
@@ -201,346 +196,6 @@ def isInGitmarkPublicRepo(gitmarkObj):
settings.BOOKMARK_SUB_PATH, gitmarkObj.hash)
return os.path.isfile(filename)
-class gitmark(object):
-
- # -- GitMarks members
- # If you add member variables you don't want in a gitmark, delete them in JOSNBlock below
- # Otherwise self.__dict__ works rong.
- uri = None #string
- hash = None #hash value
- summary = None #string
- description = None #string
- tags = [] #list of strings of tags
- time = None #ISO8601 absolute date time
- creator = None
- rights = None #creative commons rights string
- tri = [] #transitionary resource locator. IRL bit.ly, goo.gl, etc
- content = '' #content of the site. Lazyloads and should do smart local/away fetch
- title = None
- extended = None
- meta = None
- private = None
- ver = GITMARK_VER_STRING
-
- def __init__(self,uri, creator=None, dictValues=None):
- # -- temp. Force build deafults before overriding
- self.uri = uri
- self.hash = self.generateHash(uri)
- self.time = time.strftime("%Y-%m-%dT%H:%M:%SZ")
- self.creator = creator
- self.rights = 'CC BY'
- self.private = True #default to private for safety
-
- if dictValues:
- #DANGER: this is a security danger
- self.__dict__
- #TODO: Do I want to return self?
-
-
- def addTags(self, stringList):
- #if we have more than 1 quote, split by quotes
- if(stringList.count('"') > 1):
- print 'has qouted string! We fail'
- else :
- list = stringList.split(',')
- list = [ l.lstrip().rstrip() for l in list]
- #TODO: do some smart string hacking, for different strings
- # of data formatting
- self.tags.extend(list)
-
- def noContentSet(self):
- """
- returns true of this gitmark is set to 'get no content'
- """
- #TODO menoize this result, and kill the menoize if we get
- # a change to the tag. Maybe menoize to a hash of the list,
- # and if the hash changes, re-calculate?
- if 'no content' in self.tags:
- return True
- elif 'no_content' in self.tags:
- return True
- return False
-
- def __str__(self):
- return '<gitmark obj for "%s" by "%s"\n>' %(self.uri, self.creator)
-
- def setPrivacy(self, privacy):
- """ Set this gitmark to be private """
- self.private = privacy
-
- def generateHash(self, uri = None):
- """generates a hash for our URI (or the passed
- URI if it is not null"""
- if(uri == None):
- uri = self.uri
- m = hashlib.md5()
- m.update(uri)
- return m.hexdigest()
-
- def parseTitle(self, content=None):
- """ parses the tile from html content, sets it to
- our local title value, and returns the title to the caller"""
- if(content == None):
- content = self.content
- self.title = self.cls_parseTitle(content)
- return self.title
-
- def getContent(self, uri=None):
- """
- Get content from the web, and store it to our local
- content structure. IF we have a uri, gets contents from
- there instead of our local uri.
- """
- if( uri == None):
- uri = self.uri
- #FUTURE: do we want to allow a different URI to get passed in?
- self.content = self.cls_getContent(uri)
-
- def uncacheContent(self, target_file):
- """
- Reads content from our local cache if we have it,
- otherwise it will fetch that content from the web (not
- store it) and save it to the local gitmark.
- """
- if os.path.isfile(target_file) :
- fh = open(target_file,"r")
- self.content = fh.read()
- del fh
- else:
- print >>sys.stderr, ("Warning: no local content for this gitmark."
- "tryig to read from web")
- self.getContent()
-
- def setTimeIfEmpty(self):
- if self.time == None :
- self.time = time.strftime("%Y-%m-%dT%H:%M:%SZ")
-
- def cacheContent(self, target_file, content=None):
- """
- Write this gitmarks content to the target file. If this
- content is specified, then that content is written instead
- of the content in this gitmark
- """
- # -- lazily git store any existing file if necessary
- if os.path.isfile(target_file) :
- #check the md5 sum of the contet of this file,
- #if it does NOT match our new content, then
- print "do magic here to md5 sum, and cache file if needed"
- if content == None:
- content = self.content
- self.cls_saveContent(target_file, content)
-
- def addMyselfLocally(self, localGitmarkDir, localTagsDir):
- """
- This method causes a gitmark to
- add itself to the local repository.
- """
- print "not used. old code. Use for reference only"
- exit(-5)
-
- print "adding myself to the local repository"
- if(self.private != False):
- print "this is a private mark. Encrypting not yet enabled. Do not store"
- else :
- # -- write gitmark
- fname = os.path.join(localGitmarkDir,self.hash)
- #fp = open(fname,"w")
- print 'debug fwrite of file "%s"' % fp
- print '---'
- print self.JSONBlock()
- print '---'
- #fwrite(self.JOSNBlock())
- #fclose(fp)
- # add git add here
-
- # -- write tags
- fname = os.path.join(localGitmarkDir,self.hash)
- fp = open(fname,"w")
- prettyTags = self.prettyTags()
- uglyTags = self.uglyTags()
- tags = set(uglyTags.append(prettyTags))
- for tag in tags:
- fname = os.path.join(localGitmarkDir,self.hash)
- print 'tag filename "%s" ' %fname
- # add git add here
- settings.TAG_SUB_PATH
-
-
-
- def JOSNBlock(self):
- """creates and retuns a JSON text block of
- current members of this gitMark. """
- d = self.__dict__
- if 'content' in d.keys() :
- del d['content'] #remove content, we don't want that
- return json.dumps(d,indent=4)
-
- def miniJSONBlock(self):
- """ creates and returns a minimun json block, used for tag files """
- d = {'hash':self.hash, 'title':self.title, 'uri':self.uri,
- 'creator':self.creator, 'ver':self.ver }
- return json.dumps(d,indent=4)
-
-
- def prettyTags(self):
- """ tags, cleaned from delicious and make nicer looking"""
- g = []
- for t in self.tags:
- print t
- if '_' in t:
- g.append(t.replace('_',' '))
- else:
- g.append(t)
- print g
- return g
-
- def uglyTags(self):
- """ tags as gotten raw, un-prettied for search and use"""
- return self.tags
-
-
- def everyPossibleTagList(self):
- allTags = self.prettyTags()
- allTags.extend(self.uglyTags())
- allTags = set(allTags)
- return allTags
-
- @classmethod
- def cls_hydrate(cls, filename):
- """
- Create a gitmark object from files on the local filesystem.
- """
- f = open(filename,'r')
- if(f):
- jsonObj = f.read()
- f.close()
- del f
- obj = json.loads(jsonObj)
- print obj
- mark = gitmark(settings.USER_NAME)
-
-
-
- else:
- print "failed to read/load %s" %filename
- return None
-
- @classmethod
- def cls_saveContent(cls, filename, content):
- """
- """
- f = open(filename, 'w')
- f.write(content)
- f.close()
- return filename
-
- @classmethod
- def cls_generateHash(cls, text):
- m = hashlib.md5()
- m.update(text)
- return m.hexdigest()
-
- @classmethod
- def cls_getContent(cls, url):
- try:
- h = urllib.urlopen(url)
- content = h.read()
- h.close()
- h = urllib.urlopen(url)
- except IOError, e:
- print >>sys.stderr, ("Error: could not retrieve the content of a"
- " URL. The bookmark will be saved, but its content won't be"
- " searchable. URL: <%s>. Error: %s" % (url, e))
- content = ''
- except httplib.InvalidURL, e: #case: a redirect is giving me www.idealist.org:, which causes a fail during port-number search due to trailing :
- print >>sys.stderr, ("Error: url or url redirect contained an"
- "invalid URL. The bookmark will be saved, but its content"
- "won't be searchable. URL: <%s>. Error: %s" % (url, e))
- content=''
- return content
-
- @classmethod
- def cls_parseTitle(cls, content):
- re_htmltitle = re.compile(".*<title>(.*)</title>.*")
- t = re_htmltitle.search(content)
- try:
- title = t.group(1)
- except AttributeError:
- title = '[No Title]'
- return title
-
- @classmethod
- def gitAdd(cls, files, forceDateTime=None, gitBaseDir=None):
- """ add this git object's files to the local repository"""
- # TRICKY:Set the authoring date of the commit based on the imported timestamp. git reads the GIT_AUTHOR_DATE environment var.
- # TRICKTY: sets the environment over to the base directory of the gitmarks base
- cwd_dir = os.path.abspath(os.getcwd())
-
- if gitBaseDir: os.chdir(os.path.abspath(gitBaseDir))
- if forceDateTime : os.environ['GIT_AUTHOR_DATE'] = forceDateTime
- subprocess.call(['git', 'add'] + files, shell=USE_SHELL)
- if forceDateTime : del os.environ['GIT_AUTHOR_DATE']
- if gitBaseDir: os.chdir(cwd_dir)
-
- @classmethod
- def gitCommit(cls, msg, gitBaseDir = None):
- """ commit the local repository to the server"""
- # TRICKTY: sets the environment over to the base directory of the gitmarks base
- cwd_dir = os.path.abspath(os.getcwd())
- if gitBaseDir: os.chdir(os.path.abspath(gitBaseDir))
- subprocess.call(['git', 'commit', '-m', msg], shell=USE_SHELL)
- if gitBaseDir: os.chdir(cwd_dir)
-
- @classmethod
- def gitPush(cls, gitBaseDir = None):
- """ push the local origin to the master"""
- # TRICKTY: sets the environment over to the base directory of the gitmarks base
- cwd_dir = os.path.abspath(os.getcwd())
- if gitBaseDir: os.chdir(os.path.abspath(gitBaseDir))
- print os.getcwd()
- pipe = subprocess.Popen("git push origin master", shell=True) #Tricky: shell must be true
- pipe.wait()
- if gitBaseDir: os.chdir(cwd_dir)
-
-
-# @classmethod
-# def saveTagData(cls, tag, url, title, base_filename):
-# tag_filename = os.path.join(TAG_PATH, tag)
-# tag_writer = csv.writer(open(tag_filename, 'a'))
-# tag_writer.writerow([url, title, base_filename])
-# return tag_filename
-#
-# @classmethod
-# def parseTitle(cls, content):
-# re_htmltitle = re.compile(".*<title>(.*)</title>.*")
-# t = re_htmltitle.search(content)
-# try:
-# title = t.group(1)
-# except AttributeError:
-# title = '[No Title]'
-#
-# return title
-#
-# @classmethod
-# def getContent(cls, url):
-# try:
-# h = urllib.urlopen(url)
-# content = h.read()
-# h.close()
-# h = urllib.urlopen(url)
-# except IOError, e:
-# print >>sys.stderr, ("Error: could not retrieve the content of a"
-# " URL. The bookmark will be saved, but its content won't be"
-# " searchable. URL: <%s>. Error: %s" % (url, e))
-# content = ''
-# except httplib.InvalidURL, e: #case: a redirect is giving me www.idealist.org:, which causes a fail during port-number search due to trailing :
-# print >>sys.stderr, ("Error: url or url redirect contained an"
-# "invalid URL. The bookmark will be saved, but its content"
-# "won't be searchable. URL: <%s>. Error: %s" % (url, e))
-# content=''
-# return content
-
-
if __name__ == '__main__':
""" Function to run if we are running at the commandline"""
@@ -550,7 +205,7 @@ def gitPush(cls, gitBaseDir = None):
parser.add_option("-s", "--share", dest="push", action="store_true", default=False, help="push data to remote gitmarks share point if possible")
parser.add_option("-t", "--tags", dest="tags", action="store", default='notag', help="comma seperated list of tags")
parser.add_option("-m", "--message", dest="msg", action="store", default=None, help="specify a commit message (default is 'adding [url]')")
- parser.add_option("-c", "--skipcontent", dest='content', action='store_false', default=True, help="do not try to fetch content to store locall for search")
+ parser.add_option("-c", "--skipcontent", dest='content', action='store_false', default=True, help="do not try to fetch content to store locally for search")
parser.add_option("-p", "--private", dest="private", action="store_true", default=False, help="Mark this as a private tag, not to share except with for:XXX recepiants")
if len(sys.argv) <= 1:
90 gitmark_friend.py
View
@@ -9,8 +9,96 @@
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"
- autoadd_friends_tagged_bookmarks();
+ 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
+
+
+
4 services.json
View
@@ -0,0 +1,4 @@
+{
+ "com.twitter":"twitter.com",
+ "com.delicious":"delicious.com"
+}
Chris Sedlmayr

Shouldn't this be JSONBlock(self):

And in associated usage.

Far McKon

Yup, that is a type. I looked at the 3 times before I even saw the typo. Staring at code too long I guess. Good catch.

Far McKon

goddamm this stinks (test comment)

Please sign in to comment.
Something went wrong with that request. Please try again.