forked from abuya-momo/DataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.py
78 lines (48 loc) · 1.47 KB
/
register.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#coding:utf-8
from django.shortcuts import render
import os
from django.http import HttpResponse
NOTEINFOR = ".." + os.sep + "noteInfor" + os.sep #../noteInfor/ linux
FRIENDS = "friends.txt"
INTRODUCE = "introduce.txt"
ACCOUNT = "acount.txt"
NUMBER = 10000
def register(ID,username,password):
with open('count.txt','a') as f:
f.write(ID + ',' + username + ',' + password + '&\n')
f.close()
def addUser(request):
global NUMBER
username = request.GET.get('username',None)
password = request.GET.get('password',None)
ID = NUMBER + 1
register(ID,username,password)
def addFriends(ID,friendID):
if checkFriend(ID,friendID):
HttpResponse("friend is exist") #friend exist
with open((NOTEINFOR + ID + FRIENDS),'a') as f:
f.write(friendID + ',')
f.close()
def checkFriend(ID,friendID):
if not checkFileExist(ID + os.sep + FRIENDS):
return False #friend not exist
with open((ID + os.sep + FRIENDS),'r') as f:
friendInfor = f.readline()
friendInfor = friendInfor.split(',')
for friend in friendInfor:
if friend == friendID:
return True #friend exist
return False
def checkIntroduce(ID):
return checkFileExist(ID + os.sep + FRIENDS)
def getIntroduce(ID):
if not checkIntroduce(ID):
return None
with open((NOTEINFOR + os.sep + INTRODUCE),'r') as f:
introduce = f.readlines()
f.close()
return introduce
def setIntroduce(ID,introduce):
with open((NOTEINFOR + ID + os.sep + INTRODUCE),'w') as f:
f.writelines(introduce)
f.close()