本文整理汇总了Python中moments.path.Path.load_journal方法的典型用法代码示例。如果您正苦于以下问题:Python Path.load_journal方法的具体用法?Python Path.load_journal怎么用?Python Path.load_journal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moments.path.Path
的用法示例。
在下文中一共展示了Path.load_journal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_journal
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load_journal [as 别名]
def test_load_journal(self):
dest = 'zoobar/todo.txt'
p = Path(dest)
p.load_journal(create=True)
assert os.path.exists(dest)
p.remove()
assert not os.path.exists(dest)
示例2: lookup_playing
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load_journal [as 别名]
def lookup_playing(channel_id="groovesalad"):
url = "http://somafm.com/%s/played" % channel_id
response = urllib.request.urlopen(url)
html = response.read()
soup = BeautifulSoup.BeautifulSoup(html)
#print soup.prettify()
#tags = soup.findAll('div')
#tags = soup.findAll('div', 'playinc')
#container = soup.find('div',
# tags = soup.findAll('posts')
tags = soup.findAll('div', attrs={'id':'playinc'})
#print len(tags)
#print tags
parts = []
url = ''
for t in tags:
rows = t.findAll('tr')
#print len(rows)
first = rows[2]
tds = first.findAll('td')
for td in tds:
#print td
if td and len(td.contents):
link = td.findAll('a')
if len(link):
#print link
if len(link[0].contents):
text = link[0].contents[0]
url = link[0]['href']
else:
print("No link: %s" % link)
text = ''
else:
text = td.contents[0]
text = text.replace(' ', ' ')
parts.append(text)
#print content
#print parts
#print url
if os.path.exists('/c/music'):
dest = '/c/music/radio/somafm.txt'
j = Journal(dest)
tags = [ channel_id ]
else:
now = Timestamp()
today = now.compact(accuracy="day")
today_log = Path(os.path.join('/c/outgoing', now.filename()))
dest = str(today_log)
j = today_log.load_journal()
tags = [ 'music', 'radio', 'somafm', channel_id, 'plus' ]
data = " - ".join(parts)
#print data
data += '\n' + url
e = j.make(data, tags)
j.save(dest)
print("")
print(e.render())
print("Saved to: %s" % dest)
示例3: save
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load_journal [as 别名]
def save(relative=''):
# debug:
# print(dir(bottle.request.forms))
# print("Keys: %s" % (bottle.request.forms.keys()))
# print("Values: %s" % (bottle.request.forms.values()))
global path_root
if re.match('~', relative):
relative = os.path.expanduser(relative)
if not relative:
# could set a default here if it is desireable
print("NO DESTINATION SENT!")
elif not re.match('/', relative):
relative = path_root + relative
# destination = Path(relative, relative_prefix=path_root)
# now check if the destination is a directory...
# in that case, create a sortable.list name in the directory
if os.path.isdir(relative):
print("Relative directory passed in:", relative)
path = Path(relative)
print("Path loaded:", path)
name = path.name + ".list"
destination = os.path.join(relative, name)
# TODO:
# something recursive can happen here:
# having difficulty replicating...
# should work though!
# destination = path.sortable_list_path()
print("Destination:", destination)
log_name = path.name + ".list.log"
log_destination = os.path.join(relative, log_name)
else:
destination = relative
log_destination = relative + ".log"
# print(destination)
# gets a string
# could be json or text / list
content = bottle.request.forms.get('content')
# print("CONTENT:")
# print(content)
# print()
save_as = bottle.request.forms.get('format')
if destination:
if save_as in ["list"]:
dest_file = open(destination, 'w')
# print("opened: ", destination)
# print("writing (raw): ", content)
dest_file.write(content)
dest_file.close()
print("saved content to: ", destination)
# TODO:
# check the .list.log file to see if today's entry already exists
log_path = Path(log_destination)
print("Log path: ", log_path)
if log_path.exists():
j = log_path.load_journal()
else:
j = log_path.load_journal(create=True)
now = Timestamp()
now.compact(accuracy='day')
entries = j.range(now)
print(entries)
if len(entries):
print("already had today logged")
else:
j.make(content, created=now)
j.save(log_path)
print("adding new entry")
# this should be sufficient
return("Success!")
else:
return("Unknown format: " + str(save_as))
## elif save_as == "json":
## #could also do something like:
## ordered_list = json.loads(content)
## save_json(destination, ordered_list)
## #but that seems like the same thing as above
# if save() is being called via ajax,
# redirecting here only causes extra load on the server
# redirect("/text" + relative)
# redirect("/path" + relative)
#.........这里部分代码省略.........
示例4: sort
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load_journal [as 别名]
def sort(relative=''):
"""
accept a path to a moment log and enable sorting on the items
using jquery ui for a drag and drop interface
"""
global path_root
if re.match('~', relative):
relative = os.path.expanduser(relative)
if not re.match('/', relative):
relative = path_root + relative
#set some defaults here...
#if they've been changed, this will get over written on load
groups = { "all":[], "edit":[], "slide1":[], "slide2":[], "slide3":[], "slide4":[], "slide5":[], "slide6":[], "slide7":[], "slide8":[], "slide9":[], }
tab_order = ['all', 'edit', "slide1", "slide2", "slide3", "slide4", "slide5", "slide6", "slide7", "slide8", "slide9"]
path = Path(relative, relative_prefix=path_root)
print(path)
if path.exists() and path.type() == "Directory":
response = "Error: need a file name to store the meta data in<br>"
response = "You supplied a directory path: %s<br>" % path
return response
else:
parent_directory = path.parent()
if path.extension == ".txt":
#create a text journal if we don't have one
if not path.exists():
#convert images to journal
#print "PARENT: %s" % parent_directory
directory = parent_directory.load()
#print "directory: %s, of type: %s" % (directory, type(directory))
directory.create_journal(journal=path.filename)
#journal = path.load_journal(create=True)
journal = path.load_journal()
items = []
for e in journal.entries():
new_p = os.path.join(str(parent_directory), e.data.strip())
#print new_p
p = Path(new_p)
#print p.exists()
items.append(p)
#initial version of groups:
destination = Path(relative)
destination.extension = '.json'
groups['all'] = items
elif path.extension == ".json":
#we can make the initial version here...
#skip the generation of a moments log step
if not path.exists():
directory = parent_directory.load()
#print "directory: %s, of type: %s" % (directory, type(directory))
directory.sort_by_date()
directory.scan_filetypes()
groups['all'] = directory.images
else:
loaded = load_groups(str(path))
#template expects all items in groups to be Path objects.
#do that now
groups = {}
for key, value in list(loaded.items()):
groups[key] = []
for v in value:
groups[key].append(Path(v))
destination = Path(relative)
else:
#dunno!
print("UNKNOWN FILE TYPE: %s" % relative)
groups = {}
destination = None
#clean up tab_order as needed
for key in list(groups.keys()):
if not key in tab_order:
tab_order.append(key)
for item in tab_order[:]:
if item not in list(groups.keys()):
tab_order.remove(item)
print(tab_order)
#return template('sort', path=path, items=items)
return template('sort', path=path, groups=groups, destination=destination, tab_order=tab_order)