From 039d439b67d37c7cc98f18fb0636de5d05b86aed Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Fri, 18 Mar 2016 13:01:31 +0200 Subject: Added periodic CompTIA update command --- servo/management/commands/periodic.py | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 servo/management/commands/periodic.py (limited to 'servo/management/commands/periodic.py') diff --git a/servo/management/commands/periodic.py b/servo/management/commands/periodic.py new file mode 100644 index 0000000..5895e3c --- /dev/null +++ b/servo/management/commands/periodic.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +import os +import sys +import gsxws +import subprocess +from time import strftime +from django.conf import settings +from django.core.cache import caches +from django.core.management.base import BaseCommand + +from servo.models import GsxAccount + + +class Command(BaseCommand): + help = 'Peforms periodic commands' + VERBS = ('comptia',) + + def add_arguments(self, parser): + parser.add_argument('verb', type=str, choices=self.VERBS, help='Periodic command to perform') + + def handle(self, *args, **options): + if 'comptia' in options['verb']: + # Update raw CompTIA data (all product groups) + try: + act = GsxAccount.fallback() + except Exception as e: + print >> sys.stderr, 'Failed to connect to GSX (%s)' % e + sys.exit(-1) + + try: + codes = gsxws.comptia.fetch() + caches['comptia'].set('codes', codes) + except Exception as e: + print >> sys.stderr, 'Failed to fetch CompTIA codes (%s)' % e + sys.exit(-1) + + exit(0) -- cgit v1.2.3 From 1b6e5ee722f76f594e3d95dfa8d77ac2b9f2173a Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Mon, 21 Mar 2016 19:14:37 +0200 Subject: Adding GSX articles --- servo/management/commands/periodic.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'servo/management/commands/periodic.py') diff --git a/servo/management/commands/periodic.py b/servo/management/commands/periodic.py index 5895e3c..e85f9a3 100644 --- a/servo/management/commands/periodic.py +++ b/servo/management/commands/periodic.py @@ -9,25 +9,38 @@ from django.conf import settings from django.core.cache import caches from django.core.management.base import BaseCommand -from servo.models import GsxAccount +from servo.models import GsxAccount, Article class Command(BaseCommand): help = 'Peforms periodic commands' - VERBS = ('comptia',) + VERBS = ('comptia', 'articles',) def add_arguments(self, parser): parser.add_argument('verb', type=str, choices=self.VERBS, help='Periodic command to perform') def handle(self, *args, **options): - if 'comptia' in options['verb']: - # Update raw CompTIA data (all product groups) - try: - act = GsxAccount.fallback() - except Exception as e: - print >> sys.stderr, 'Failed to connect to GSX (%s)' % e - sys.exit(-1) - + try: + act = GsxAccount.fallback() + except Exception as e: + print >> sys.stderr, 'Failed to connect to GSX (%s)' % e + sys.exit(-1) + + if 'articles' in options['verb']: # Update GSX articles + articles = gsxws.comms.fetch() + for a in articles: + try: + article = Article.from_gsx(a) + try: + content = gsxws.comms.content(article.gsx_id) + article.content = content.articleContent + except Exception as e: + pass + article.save() + except ValueError as e: + pass + + if 'comptia' in options['verb']: # Update raw CompTIA data (all product groups) try: codes = gsxws.comptia.fetch() caches['comptia'].set('codes', codes) -- cgit v1.2.3