Permalink
Browse files

Quick and dirty to make cron update work by date

  • Loading branch information...
1 parent ad2db5a commit ce7eb10c8d2f034cb397d46197b3fa02518bf289 @tualatrix committed Apr 1, 2012
Showing with 20 additions and 7 deletions.
  1. +18 −4 imtx/apps/blog/management/commands/update_pm25.py
  2. +1 −2 imtx/scripts/update_pm25.sh
  3. +1 −1 imtx/views.py
View
22 imtx/apps/blog/management/commands/update_pm25.py
@@ -11,7 +11,21 @@
class Command(BaseCommand):
def handle(self, *args, **options):
pmdata = get_pm25_dict()
- for city, data in pmdata['cities'].items():
- message = u'%s %s空气质量】' % (pmdata['date'], city) + u'PM2.5浓度: %(concentration)s ug/m3, AQI: %(aqi)s, 等级: %(category)s' % data
- os.system(u'twitter set "%s"' % message)
- time.sleep(3)
+
+ if os.path.exists('timestamp'):
+ timestamp = open('timestamp').read().strip()
+ else:
+ timestamp = ''
+
+ if timestamp != pmdata['date']:
+ for city, data in pmdata['cities'].items():
+ message = u'%s %s空气质量】' % (pmdata['date'], city) + u'PM2.5浓度: %(concentration)s ug/m3, AQI: %(aqi)s, 等级: %(category)s' % data
+ print message
+ os.system(u'twitter set "%s"' % message)
+ time.sleep(3)
+
+ f = open('timestamp', 'w')
+ f.write(pmdata['date'])
+ f.close()
+ else:
+ print 'No update yet'
View
3 imtx/scripts/update_pm25.sh
@@ -1,6 +1,5 @@
#!/bin/bash
cd /home/tualatrix/public_html/imtx.me/imtx/imtx/
+workon imtx.me
/home/tualatrix/public_html/imtx.me/bin/python manage.py update_pm25
-
-
View
2 imtx/views.py
@@ -52,7 +52,7 @@ def get_pm25_dict():
content = urllib.urlopen('http://app.zjepb.gov.cn:8080/wasdemo/search?channelid=121215').read()
soup = BeautifulSoup(content)
- data['date'] = soup.find(color='red').text
+ data['date'] = soup.find(id='1')['value']
data['cities'] = OrderedDict()
for td in soup.findAll(height='23'):

0 comments on commit ce7eb10

Please sign in to comment.