예제 #1
0
def read(request):
    #get initial time from feed
    getInitialFeed = feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH)
    lastModified = getInitialFeed.entries[0].modified
    while True:
        #keep checking for feed
        scrapedFeed = feedparser.parse(PROTO+USERNAME+":"+PASSWORD+"@"+SERVER+PATH)
        scrapedModified = scrapedFeed.entries[0].modified #get time when feed is being checked
        if lastModified < scrapedModified: #if there is a new message (timestamp is greater than the last time the feed was checked)
            lastModified = scrapedModified #update the last time a new message arrived
            name1 = scrapedFeed.entries[0].author_detail.name #get details
            email1 = scrapedFeed.entries[0].author_detail.email
            content = str(scrapedFeed.entries[0].title) 
            
            try:
                user = User.objects.get(email = email1) #try to get user who sent it from database
            except:
                x = find(name1,' ')+1 #if user does not exist, create user in database
                first = name1[:x]
                addUser(name1, email1, first)    
                user = User.objects.get(email = email1)
            
            time1 = str(scrapedModified) #parse into string so it can be sliced
            time2 = time1[:10]+' '+time1[11:19] #edit string into a time that can be parsed
            time3 = datetime.strptime(time2, '%Y-%m-%d %H:%M:%S') #parse string into a datetime object
            underscorename = convert(user.username,' ','_')
            addMessage(user, email1, content, time3, underscorename) #add new Message object to database
        
        current = str(time.strftime('%X')) #get current time
        today = date.today() #get day of week today
        dayofweek = today.isoweekday() #get day of week

        check(current, dayofweek)
            
    return HttpResponse()
예제 #2
0
파일: views.py 프로젝트: alex0531/-Manage
def read(request):
    getInitialFeed = feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH)
    lastModified = getInitialFeed.entries[0].modified

    while True:
        scrapedFeed = feedparser.parse(PROTO+USERNAME+":"+PASSWORD+"@"+SERVER+PATH)
        scrapedModified = scrapedFeed.entries[0].modified
        if lastModified < scrapedModified: #if there is a new message
            lastModified = scrapedModified
            name1 = scrapedFeed.entries[0].author_detail.name #get details
            email1 = scrapedFeed.entries[0].author_detail.email
            content = str(scrapedFeed.entries[0].title) 
            
            try:
                user = User.objects.get(email = email1) #try to get user who sent it from database
            except:
                x = find(name1,' ')+1 #if user does not exist, create user in database
                first = name1[:x]
                addUser(name1, email1, first)    
                user = User.objects.get(email = email1)
            
            time1 = str(scrapedModified) #parse into string so it can be sliced
            time2 = time1[:10]+' '+time1[11:19] #edit string into a time that can be parsed
            time3 = datetime.strptime(time2, '%Y-%m-%d %H:%M:%S') #parse string into a datetime object
            addMessage(user, email1, content, time3) #add new Message object to database
        
        current = str(time.strftime('%X'))
        today = date.today()
        dayofweek = today.isoweekday()

        check(current, dayofweek)
            
    return HttpResponse()