snose

Check-in [7dedaed4cc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Python3 compatibility - iteritems vs items

I think that might be all that's needed. This was never super duper advanced
code.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | python3
Files: files | file ages | folders
SHA3-256: 7dedaed4cc9e5596a4e20c8d2f5d7d558753e503719fc831eea08a1d5dc95eb2
User & Date: atomicules 2018-10-06 17:56:57
Context
2018-10-11
07:54
Merge in Python3 stuff check-in: 5d0589b3be user: simon tags: trunk, master
2018-10-06
17:56
Python3 compatibility - iteritems vs items

I think that might be all that's needed. This was never super duper advanced
code. Leaf check-in: 7dedaed4cc user: atomicules tags: python3

16:41
Start of Python3 compatibility

It's about time... print statements are the easy ones. check-in: d20f7e7998 user: atomicules tags: python3

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to snose.py.

1
2
3

4
5
6
7
8
9
10
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
...
153
154
155
156
157
158
159




160

161
162
163
164
165
166
167
...
227
228
229
230
231
232
233




234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/python
#snose - Simplenote Object Synchronisation (Explicit)


import json
import simplenote #Need to install this
import os.path, time
from optparse import OptionParser
import netrc

def main():
................................................................................
	try:
		remote = snclient.get_note(key)	
	except IOerror as e:
		print("Failed to find that note on Simplenote")
		print(e)
	else:
		#Write file
		try: 
			with open(filename, 'w') as f:
				f.write(remote[0]['content'])
		except IOError as e:
			print("Failed to create local copy of that note")
			print(e)
		else:
			#Update index
			try:
				snose[filename] = {'key': remote[0]['key'], 'version': remote[0]['version'], 'modifydate': float(os.path.getmtime(filename)) } #Need to set as local modified date as otherwise will want to sync it straight away.
				#Write back out
				with open('.snose', 'w') as f:
					json.dump(snose, f, indent=2)
			except IOError as e:
				 print("Failed to update .snose index file")
				 print("But note was created locally. Try sniffing the file to add it to the index.")


def blow(snclient, key):
	#With given key from .snose file, roll back to the previous version

	#1) Check exists in .snose index
	#2) Get previous version of remote
................................................................................
	#5) Update index file with results

	#1) Check exists in .snose index
	try:
		with open('.snose', 'r') as f:
			snose = json.load(f)
		#Need to get filename of note, loop through, performance should be fine as .snose likely to be small




		filename = [name for name, local in snose.iteritems() if local['key'] == key][0]

		print("Attempting to rollback file %s" % filename)
	except IOError as e:
		print("Note doesn't exist in local .snose index")
	else:
		#2) Get previous version of remote
		try:
			#fetch once to know version
................................................................................
	try:
		with open('.snose', 'r') as f:
			snose = json.load(f)
	except IOError as e:
		print('Error reading Index file')
	else:
		#Need to iterate through list.




		for name, local in snose.iteritems():
			#First of all check for local modifications
			sysmodifydate = float(os.path.getmtime(name))
			if sysmodifydate > float(local['modifydate']): #ensure full timestamp
				if not dry:
				#Update remote
					try:
						with open(name, 'r') as f:
							content = f.read()
					except IOError as e:
						print("Failed to read local note %s" % name)
						print("Skipping synchronisation for this note")
					else: 
						try:
							returned = snclient.update_note({'key': local['key'], 'version': local['version'], 'content': content, 'modifydate': sysmodifydate })
							print("Updated remote version of %s" % name)
						except IOError as e:
							print("Failed to update remote verison of local note %s" % name)
						else:
							#Get returned metadata



>







 







|













|
|







 







>
>
>
>
|
>







 







>
>
>
>
|











|







1
2
3
4
5
6
7
8
9
10
11
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/python
#snose - Simplenote Object Synchronisation (Explicit)

import sys
import json
import simplenote #Need to install this
import os.path, time
from optparse import OptionParser
import netrc

def main():
................................................................................
	try:
		remote = snclient.get_note(key)	
	except IOerror as e:
		print("Failed to find that note on Simplenote")
		print(e)
	else:
		#Write file
		try:
			with open(filename, 'w') as f:
				f.write(remote[0]['content'])
		except IOError as e:
			print("Failed to create local copy of that note")
			print(e)
		else:
			#Update index
			try:
				snose[filename] = {'key': remote[0]['key'], 'version': remote[0]['version'], 'modifydate': float(os.path.getmtime(filename)) } #Need to set as local modified date as otherwise will want to sync it straight away.
				#Write back out
				with open('.snose', 'w') as f:
					json.dump(snose, f, indent=2)
			except IOError as e:
				print("Failed to update .snose index file")
				print("But note was created locally. Try sniffing the file to add it to the index.")


def blow(snclient, key):
	#With given key from .snose file, roll back to the previous version

	#1) Check exists in .snose index
	#2) Get previous version of remote
................................................................................
	#5) Update index file with results

	#1) Check exists in .snose index
	try:
		with open('.snose', 'r') as f:
			snose = json.load(f)
		#Need to get filename of note, loop through, performance should be fine as .snose likely to be small
		if sys.version_info < (3, 0):
			sitems = snose.iteritems()
		else:
			sitems = snose.items()
		filename = [name for name, local in sitems if local['key'] == key][0]

		print("Attempting to rollback file %s" % filename)
	except IOError as e:
		print("Note doesn't exist in local .snose index")
	else:
		#2) Get previous version of remote
		try:
			#fetch once to know version
................................................................................
	try:
		with open('.snose', 'r') as f:
			snose = json.load(f)
	except IOError as e:
		print('Error reading Index file')
	else:
		#Need to iterate through list.
		if sys.version_info < (3, 0):
			sitems = snose.iteritems()
		else:
			sitems = snose.items()
		for name, local in sitems:
			#First of all check for local modifications
			sysmodifydate = float(os.path.getmtime(name))
			if sysmodifydate > float(local['modifydate']): #ensure full timestamp
				if not dry:
				#Update remote
					try:
						with open(name, 'r') as f:
							content = f.read()
					except IOError as e:
						print("Failed to read local note %s" % name)
						print("Skipping synchronisation for this note")
					else:
						try:
							returned = snclient.update_note({'key': local['key'], 'version': local['version'], 'content': content, 'modifydate': sysmodifydate })
							print("Updated remote version of %s" % name)
						except IOError as e:
							print("Failed to update remote verison of local note %s" % name)
						else:
							#Get returned metadata