def handle(self, *args, **options):
        s = io.StringIO()
        err = False

        state = defaultdict(dict)
        for provider in MessagingProvider.objects.filter(
                active=True).order_by('classname'):
            impl = get_messaging(provider)

            try:
                result, out = impl.check_messaging_config(
                    state[provider.classname])
            except Exception as e:
                result = False
                out = "EXCEPTION: {}\n".format(e)

            if out:
                s.write("{}\n".format(provider.internalname))
                s.write("{}\n".format('-' * len(provider.internalname)))
                s.write(out)
                s.write("\n\n")
            if not result:
                err = True

        if s.tell() != 0:
            print(s.getvalue())

        if err:
            sys.exit(1)
    def handle(self, *args, **options):
        curs = connection.cursor()
        curs.execute("SELECT pg_try_advisory_lock(983231)")
        if not curs.fetchall()[0][0]:
            raise CommandError(
                "Failed to get advisory lock, existing fetch_direct_messages process stuck?"
            )

        err = False

        for provider in MessagingProvider.objects.raw(
                "SELECT * FROM confreg_messagingprovider mp WHERE active AND series_id IS NOT NULL AND EXISTS (SELECT 1 FROM confreg_conferencemessaging m WHERE m.provider_id=mp.id AND (m.privatebcast OR m.notification OR m.orgnotification))"
        ):
            impl = get_messaging(provider)

            try:
                with transaction.atomic():
                    (lastpoll,
                     checkpoint) = impl.poll_incoming_private_messages(
                         provider.private_lastpoll,
                         provider.private_checkpoint)
                    provider.private_lastpoll = lastpoll
                    provider.private_checkpoint = checkpoint
                    provider.save(update_fields=[
                        'private_lastpoll', 'private_checkpoint'
                    ])
            except Exception as e:
                print("Failed to poll {} for direct messages: {}".format(
                    provider, e))
                err = True

        if err:
            # Error message printed earlier, but we need to exit with non-zero exitcode
            # to flag the whole job as failed.
            sys.exit(1)
Esempio n. 3
0
 def _get_messaging_from_uid(uid):
     if uid not in _cached_messaging:
         try:
             mp = MessagingProvider.objects.get(
                 classname='postgresqleu.util.messaging.twitter.Twitter',
                 config__accountid=uid,
                 series__isnull=False,
             )
             _cached_messaging[uid] = (mp, get_messaging(mp))
         except MessagingProvider.DoesNotExist:
             return None, None
     return _cached_messaging[uid]
    def handle(self, *args, **options):
        curs = connection.cursor()
        curs.execute("SELECT pg_try_advisory_lock(981231)")
        if not curs.fetchall()[0][0]:
            raise CommandError(
                "Failed to get advisory lock, existing fetch_media_posts process stuck?"
            )

        err = False

        for provider in MessagingProvider.objects.filter(
                active=True, series__isnull=False,
                route_incoming__isnull=False):
            impl = get_messaging(provider)

            polltime = timezone.now()
            num = 0
            try:
                with transaction.atomic():
                    for post in impl.poll_public_posts(
                            provider.public_lastpoll,
                            provider.public_checkpoint):
                        # Update our checkpoint *first*, if it happens that we have already
                        # seen everything.
                        provider.public_checkpoint = max(
                            provider.public_checkpoint, post['id'])

                        if store_incoming_post(provider, post):
                            num += 1
                    # Always save last polled time, and updated checkpoint if it changed
                    provider.public_lastpoll = polltime
                    provider.save(
                        update_fields=['public_checkpoint', 'public_lastpoll'])
                if num:
                    print("Polled {} new posts from {}".format(num, provider))
            except Exception as e:
                print("Failed to poll {}: {}".format(provider, e))
                err = True

        if err:
            # Error message printed earlier, but we need to exit with non-zero exitcode
            # to flag the whole job as failed.
            sys.exit(1)
Esempio n. 5
0
    def get_dynamic_preview(self, conference, fieldname, s):
        maxlens = "Max lengths are: {}".format(', '.join(['{}: {}'.format(mess.provider.internalname, get_messaging(mess.provider).max_post_length) for mess in conference.conferencemessaging_set.select_related('provider').filter(broadcast=True, provider__active=True)]))
        if fieldname == 'content_template':
            # Generate a preview of 3 (an arbitrary number) sessions
            posts = [self.form.generate_tweet(conference, session, s) for session in ConferenceSession.objects.filter(conference=conference, status=1, cross_schedule=False)[:3]]

            sesslist = list(ConferenceSession.objects.filter(conference=conference, status=1, cross_schedule=False))
            if sesslist:
                longest = max((get_shortened_post_length(self.form.generate_tweet(conference, session, s)) for session in sesslist))
            else:
                longest = 0

            previews = "\n\n".join([
                "{}\n\n------------------------------- (length {})".format(
                    p,
                    get_shortened_post_length(p),
                )
                for p in posts
            ])
            return HttpResponse("{}\n\nLongest to generate: {} ({})\n".format(previews, longest, maxlens), content_type='text/plain')
Esempio n. 6
0
def messaging_webhook(request, providerid, token):
    provider = get_object_or_404(MessagingProvider,
                                 id=providerid,
                                 config__webhook__token=token)
    impl = get_messaging(provider)
    return impl.process_webhook(request)