コード例 #1
0
ファイル: signals.py プロジェクト: coders-circle/notifica
def new_post(sender, instance, created, **kwargs):
    post = instance
    if created:
        title = ""
        if post.title and post.title != "":
            title = post.title

        users = get_post_users(post)
        upks = list(set([u.pk for u in users]))

        tokens = GcmRegistration.objects.filter(user__pk__in=upks).values_list('token', flat=True)
        notify(tokens, getUserName(post.posted_by), title)
コード例 #2
0
ファイル: views.py プロジェクト: coders-circle/notifica
    def post(self, request):
        context = {}
        context["users"] = User.objects.filter(
            pk__in=GcmRegistration.objects.all().values_list(
                'user', flat=True))
        request.user.profile = UserProfile.objects.get(
            user=request.user).profile

        try:
            title = request.POST['title']
            message = request.POST['message']

            user = request.POST['user']
            tokens = GcmRegistration.objects.filter(
                user__pk=user).values_list('token', flat=True)

            notify(tokens, title, message)

        except Exception as e:
            context["error"] = str(e)

        return render(request, "main/notify.html", context)
コード例 #3
0
ファイル: song.py プロジェクト: legoktm/radio-dl
 def play(self):
     main.notify(u'Now playing: {0}'.format(unicode(self)))
     main.playback(self.filename)
コード例 #4
0
ファイル: notify.py プロジェクト: lassa97/100tipy
def notifications(bus, message):
    for arg in message.get_args_list():
        if str(arg) == "Spotify":
            db_connect.insert()
            main.notify()
コード例 #5
0
    def test_notify(self):
        with unittest.mock.patch('requests.post') as mock:
            main.notify(
                [
                    {
                        'namespace': 'ns-1',
                        'name': 'pod-1',
                        'annotations': {
                            'logmein.com/slack': '#some-team',
                        },
                        'eviction_time': 'a day from now',
                    },
                    {
                        'namespace': 'ns-2',
                        'name': 'pod-2',
                        'annotations': {
                            'logmein.com/slack': '@some.person',
                        },
                        'eviction_time': '21 hours from now',
                    },
                ],
                main.parse_args([
                    '--slack-webhook=https://slack-test.com/',
                    '--slack-target=#admin-notifications',
                    '--slack-admin-contact=#admin-team',
                    '--slack-target-annotation=logmein.com/slack',
                ]),
            )
            self.assertEqual(len(mock.mock_calls), 3)
            self.assertTrue(any(
                (
                    c[2]['json']['channel'] == '#some-team' and
                    len(c[2]['json']['attachments']) == 1 and
                    '#admin-team' in c[2]['json']['text'] and
                    'a day from now' in c[2]['json']['attachments'][0]['pretext'] and
                    'ns-1' in c[2]['json']['attachments'][0]['text'] and
                    'pod-1' in c[2]['json']['attachments'][0]['text']
                )
                for c in mock.mock_calls
            ))
            self.assertTrue(any(
                (
                    c[2]['json']['channel'] == '@some.person' and
                    len(c[2]['json']['attachments']) == 1 and
                    '#admin-team' in c[2]['json']['text'] and
                    '21 hours from now' in c[2]['json']['attachments'][0]['pretext'] and
                    'ns-2' in c[2]['json']['attachments'][0]['text'] and
                    'pod-2' in c[2]['json']['attachments'][0]['text']
                )
                for c in mock.mock_calls
            ))
            self.assertTrue(any(
                (
                    c[2]['json']['channel'] == '#admin-notifications' and
                    len(c[2]['json']['attachments']) == 2 and
                    '#admin-team' in c[2]['json']['text'] and
                    any(
                        (
                            'a day from now' in a['pretext'] and
                            'ns-1' in a['text'] and
                            'pod-1' in a['text']
                        ) for a in c[2]['json']['attachments']
                    ) and
                    any(
                        (
                            '21 hours from now' in a['pretext'] and
                            'ns-2' in a['text'] and
                            'pod-2' in a['text']
                        ) for a in c[2]['json']['attachments']
                    )

                )
                for c in mock.mock_calls
            ))
コード例 #6
0
while True:
    try:
        reminder_list = main.get_reminder()
        for i in reminder_list:
            index = reminder_list.index(i)
            date, time = main.get_time_of_reminder(index)
            date = list(map(int, date.split("-")))
            time = list(map(int, time.split(":")))
            ctime = datetime.now().strftime("%H:%M")
            cdate = datetime.now().strftime("%d-%m-%Y")
            ctime = list(map(int, ctime.split(":")))
            cdate = list(map(int, cdate.split("-")))
            Checkup = check_is_every(index)
            if  Checkup == "Every Year" and cdate[0] == date[0] and cdate[1] == date[1] and ctime[0] \
               == time[0] and ctime[1] == time[1] and cdate[2] not in check(index):
                main.notify(i)
                update_reminder(cdate[2], "year")
            if Checkup == "Every Day" and time[0] == ctime[0] and time[
                    1] == ctime[1] and cdate[0] not in check(index):
                main.notify(i)
                update_reminder(cdate[0], "date")
            if Checkup == 'Day' and date[0] == cdate[0] and date[1] == cdate[1] \
              and date[2] == cdate[2] and time[0] == ctime[0] and time[1] == ctime[1]:
                main.notify(i)
                with open(".Remind.json", "r") as f:
                    data = json.load(f)
                    data["Reminder"].pop(index)
                    with open(".Remind.json", "w") as f:
                        json.dump(data, f, indent=3)
    except:
        continue
コード例 #7
0
def send_facebook_message(msg, client):
    notify("You've got a new message", msg)
    pass