Last active
December 25, 2015 18:09
-
-
Save sugiana/7018170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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