Beispiel #1
0
def mail(request):
  access_token = request.session['access_token']
  user_email = request.session['user_email']
  # If there is no token in the session, redirect to home
  if not access_token:
    return HttpResponseRedirect(reverse('tutorial:home'))
  else:
    messages = get_my_messages(access_token, user_email)
    context = { 'messages': messages['value'] }
    return render(request, 'tutorial/mail.html', context)
    
# MIT License: 
 
# Permission is hereby granted, free of charge, to any person obtaining 
# a copy of this software and associated documentation files (the 
# ""Software""), to deal in the Software without restriction, including 
# without limitation the rights to use, copy, modify, merge, publish, 
# distribute, sublicense, and/or sell copies of the Software, and to 
# permit persons to whom the Software is furnished to do so, subject to 
# the following conditions: 
 
# The above copyright notice and this permission notice shall be 
# included in all copies or substantial portions of the Software. 
 
# THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Beispiel #2
0
def mail(request):
    access_token = request.session['access_token']
    # If there is no token in the session, redirect to home
    if not access_token:
        return HttpResponseRedirect(reverse('tutorial:home'))
    else:
        messages = get_my_messages(access_token)
        return HttpResponse('Messages: {0}'.format(messages))
def mail(request):
    access_token = request.session['access_token']
    # If there is no token in the session, redirect to home
    if not access_token:
        return HttpResponseRedirect(reverse('tutorial:home'))
    else:
        messages = get_my_messages(access_token)
        return HttpResponse('Messages: {0}'.format(messages))
Beispiel #4
0
def mail(request):
    access_token = get_access_token(request,request.build_absolute_uri(reverse('tutorial:gettoken')))
    if not access_token:
        return HttpResponseRedirect(reverse('tutorial:home'))
    else:
        messages = get_my_messages(access_token)
        context = {'messages':messages['value']}
        return render(request, 'tutorial/mail.html',context)
Beispiel #5
0
def mail(request):
  access_token = get_access_token(request, request.build_absolute_uri(reverse('tutorial:gettoken')))
  # If there is no token in the session, redirect to home
  if not access_token:
    return HttpResponseRedirect(reverse('tutorial:home'))
  else:
    messages = get_my_messages(access_token)
    context = { 'messages': messages['value'] }
    return render(request, 'tutorial/mail.html', context)
Beispiel #6
0
def mail(request):
  access_token = request.session['access_token']
  user_email = request.session['user_email']
  # If there is no token in the session, redirect to home
  if not access_token:
    return HttpResponseRedirect(reverse('tutorial:home'))
  else:
    messages = get_my_messages(access_token, user_email)
    context = { 'messages': messages['value'] }
    return render(request, 'tutorial/mail.html', context)
Beispiel #7
0
def mail(request):
  access_token = get_access_token(request, request.build_absolute_uri(reverse('tutorial:gettoken')))
  user_email = request.session['user_email']
  # If there is no token in the session, redirect to home
  if not access_token:
    return HttpResponseRedirect(reverse('tutorial:home'))
  else:
    messages = get_my_messages(access_token, user_email)
    context = { 'messages': messages['value'] }
    return render(request, 'tutorial/mail.html', context)
Beispiel #8
0
def mail(request):
    access_token = get_access_token(request, request.build_absolute_uri(reverse('tutorial:gettoken')))
  # If there is no token in the session, redirect to home
    if not access_token:
        return HttpResponseRedirect(reverse('tutorial:home'))
    else:
        messages = get_my_messages(access_token)
    #Получаем список непрочитанных писем
        i=0
        while i in range(len(messages['value'])):
            if messages['value'][i]['isRead']!=False:
                messages['value'].pop(i)
            else:
                i+=1
    #сделали список

        events = get_my_events(access_token)
        i=0
        while i<len(events['value']):
            t = events['value'][i]['start']['dateTime'][11:19]
            d = events['value'][i]['start']['dateTime'][:10]
            if d == str(datetime.date.today()):
                events['value'][i]['start']['date']=d
                events['value'][i]['start']['time']=t
                i+=1
            else:
                events['value'].pop(i)

        me = get_me(access_token)

#получаем погоду
        link_to_site = 'https://community-open-weather-map.p.rapidapi.com/weather'
        headers={
            'X-RapidAPI-Host': 'community-open-weather-map.p.rapidapi.com',
            'X-RapidAPI-Key': '5aabc22e25msh45d6df4abdd28d0p1a4479jsn10ea7369318e'
                }
        parameters = {
                'q':'Ryazan,ru',
                'units':'metric',
                }
        weather = requests.get(link_to_site, headers=headers, params=parameters)
        current_weather = weather.json()

        try:
            context = {
                    'messages': messages['value'],
                    'emails_counter': len(messages['value']),
                    'events': events['value'],
                    'events_counter': len(events['value']),
                    'user_name': me['displayName'],
                    'city_weather': current_weather['main']['temp']
                    }
            return render(request, 'tutorial/mail.html', context)
        except:
            print(messages)
Beispiel #9
0
def mail(request):
  access_token = request.session['access_token']
  user_email = request.session['user_email']
  # If there is no token in the session, redirect to home
  if not access_token:
  	return HttpResponseRedirect(reverse('tutorial:home'))
  else:
  	messages = get_my_messages(access_token, user_email)
  	if 'value' not in messages:
  		return render(request, 'tutorial/mail.html', dict())
  	for i in range(0, len(messages['value'])):
  		messages['value'][i]['Body']['Content'] = html.fromstring(messages['value'][i]['Body']['Content']).text_content() 	
  		pickle.dump( messages['value'][i]['Body']['Content'], open( "save.p", "wb" ), protocol=2 )
  		os.system("py tokenizer.py")
  		a = pickle.load(open("temp.p", "rb"))
  		messages['value'][i]['Body']['Keywords'] = (','.join(a))
  	context = { 'messages': messages['value'] }
  	return render(request, 'tutorial/mail.html', context)