コード例 #1
0
 def __init__(self, option=None):
     super()
     if not option:
         option = settings.DEFAULT_FILE_STORAGE
     self.cos = ibm_boto3.client(
         "s3",
         ibm_api_key_id=envconfig('COS_API_KEY_ID'),
         ibm_service_instance_id=envconfig('COS_INSTANCE_CRN'),
         config=Config(signature_version='oauth'),
         endpoint_url=envconfig('COS_ENDPOINT'),
     )
コード例 #2
0
ファイル: models.py プロジェクト: Ashwin-Pokharel/dewi
def assignment_notification(sender, instance, **kwargs):
    client = Client(envconfig('TWILIO_ACCOUNT_SID'),
                    envconfig('TWILIO_AUTH_TOKEN'))
    class_part = instance.class_part
    available_date = instance.available_start.strftime("%b/%d/%y %I:%M:%S %p")
    due_data = instance.available_end.strftime("%b/%d/%y %I:%M:%S %p")
    message = "New assignment! from: {0}\n\t- Name: {1}\n\t- Available on: {2}\n\t-Due date: {3}  \n Good Luck!! You " \
              "got this! 😀".format(str(class_part) , instance.name , available_date , due_data)
    for student in class_part.students.all():
        phone = str(student.user.phone_number)
        sent = client.messages.create(body=message,
                                      from_='+12027653536',
                                      to=phone)
コード例 #3
0
 def delete(self, name):
     if self.exists(name):
         try:
             response = self.cos.delete_object(
                 Bucket=envconfig("COS_BUCKET_IBM"), Key=name)
             print(response)
         except Exception as e:
             raise Exception
     return False
コード例 #4
0
 def exists(self, name):
     try:
         self.cos.get_object(Bucket=envconfig("COS_BUCKET_IBM"), Key=name)
         return True
     except ClientError as e:
         if e.response['Error']['Code'] == "404":
             return False
         else:
             return False
コード例 #5
0
 def _open(self, name, mode="rb"):
     try:
         new_file = NamedTemporaryFile(delete=False)
         with open(new_file.name, "wb") as data:
             self.cos.download_fileobj(Bucket=envconfig("COS_BUCKET_IBM"),
                                       Key=name,
                                       Fileobj=data)
         return new_file
     except Exception as e:
         print(Exception, e)
         raise Exception
コード例 #6
0
 def _save(self, name, content):
     try:
         new_file = transform(content)
         with open(new_file.name, "rb") as f:
             self.cos.upload_fileobj(f, envconfig("COS_BUCKET_IBM"), name)
         new_file.close()
         return name
     except FileNotFoundError:
         raise FileNotFoundError
     except Exception as e:
         raise Exception
コード例 #7
0
ファイル: views.py プロジェクト: Ashwin-Pokharel/dewi
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from ibmUsers.models import User, Student
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated
from twilio.rest import Client
from decouple import config as envconfig
from django.db.models.signals import pre_delete, pre_save, post_save
from django.dispatch.dispatcher import receiver

# Create your views here.
client = Client(envconfig('TWILIO_ACCOUNT_SID'),
                envconfig('TWILIO_AUTH_TOKEN'))


@api_view(['GET'])
@permission_classes([IsAuthenticated])
def sendMessage(request):
    user = request.user
    phone = str(Student.objects.get(user=user).user.phone_number)
    message = client.messages.create(body="your'e doing great :-)!",
                                     from_='+12027653536',
                                     to=phone)
    return Response(status=200, data="text sent")


@api_view(['POST'])
@permission_classes([IsAuthenticated])
def receiveInput(request):
    print(request.data)