I have a python script that extracts links from specified sites and I want to make a single page webapp out of it using Django. This is my first Python and Django project so I want it to be as simple as possible to avoid any fustration but I'm kinda stuck.
this is my views.py
from django.http import HttpResponse
from bs4 import BeautifulSoup
import urllib2, sys
import urlparse
import re
import time, threading
def businessghana(request):
site = "http://www.businessghana.com/portal/jobs"
hdr = {'User-Agent' : 'Mozilla/5.0'}
req = urllib2.Request(site, headers=hdr)
jobpass = urllib2.urlopen(req)
soup = BeautifulSoup(jobpass)
for tag in soup.find_all('a', href = True):
tag['href'] = urlparse.urljoin('http://www.businessghana.com/portal/', tag['href'])
return map(str, soup.find_all('a', href = re.compile('.getJobInfo')))
threading.Timer(3600, businessghana).start()
There are about 10 of these functions for 10 different sites but they are of similar nature so for the Django project I'm using only 1 one of them. Again, to keep it simple and avoid fustration
this is my urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^hello/$', 'listing.views.businessghana'),
url(r'^admin/', include(admin.site.urls)),
)
this is my models.py:
(I think I'm spewing nonsense but this is the best i could come up with)
class jobLinks(models.Model):
links = models.CharField(max_length = 200)
pub_date = models.DateTimeField('date retrieved')
def __unicode__(self):
return self.links
When I visit the url:
127.0.0.1:8000/hello/
I get the error 'list' object has no attribute 'status_code'.
This is suppose to be a single page site that simply displays the links that were retrieved from the functions in the views. I have other plans to make it a bit more complex but I want to start with this.
Please what am I missing?
Is the models.py content making any sense?
Thanks in advance