Skip to content

Instantly share code, notes, and snippets.

@sugiana
Last active December 25, 2015 18:09
Show Gist options
  • Save sugiana/7018170 to your computer and use it in GitHub Desktop.
Save sugiana/7018170 to your computer and use it in GitHub Desktop.
import os
def clean(s):
s = s.strip()
if s.find('http://') == 0:
s = s[7:]
if s.find('www.') == 0:
s = s[4:]
return s
def baca():
if os.path.exists(filename):
f = open(filename)
s = f.read()
f.close()
return s.splitlines()
return []
def tulis():
lines = baca()
if new in lines:
return
lines.append(new)
s = '\n'.join(lines)
f = open(filename, 'w')
f.write(s)
f.close()
return True
filename = 'data.txt'
while True:
new = raw_input('Tulis: ')
new = clean(new)
if not new:
break
if tulis():
print('Data sudah ditambahkan di %s' % filename)
else:
print('Data itu sudah ada di %s' % filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment