i'm trying use file i've created called my_addqueue.py located here
src\ blog\ my_addqueue.py
and function i' trying use in same directory
src\ blog\ my_addqueue.py my_scrapy.py
i trying learn how use redis django app. when run
python blog/my_addqueue.py
i following error message
parent module '' not loaded, cannot perform relative import.
here code
my_scraps.py
def p_panties(): def swappo(): user_one = ' "mozilla/5.0 (windows nt 6.0; wow64; rv:24.0) gecko/20100101 firefox/24.0" ' user_two = ' "mozilla/5.0 (macintosh; intel mac os x 10_7_5)" ' user_thr = ' "mozilla/5.0 (windows nt 6.3; trident/7.0; rv:11.0) gecko" ' user_for = ' "mozilla/5.0 (macintosh; intel mac os x x.y; rv:10.0) gecko/20100101 firefox/10.0" ' agent_list = [user_one, user_two, user_thr, user_for] = random.choice(agent_list) return headers = { "user-agent": swappo(), "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "accept-charset": "iso-8859-1,utf-8;q=0.7,*;q=0.3", "accept-encoding": "gzip,deflate,sdch", "accept-language": "en-us,en;q=0.8", } pan_url = 'http://www.examop.com' shtml = requests.get(pan_url, headers=headers) soup = beautifulsoup(shtml.text, 'html5lib') video_row = soup.find_all('div', {'class': 'post-start'}) name = 'pan videos' if os.getenv('_system_name') == 'osx': author = user.objects.get(id=2) else: author = user.objects.get(id=3) def youtube_link(url): youtube_page = requests.get(url, headers=headers) soupdata = beautifulsoup(youtube_page.text, 'html5lib') video_row = soupdata.find_all('p')[0] entries = [{'text': div, } div in video_row] tubby = str(entries[0]['text']) urls = re.findall('http[s]?://(?:[a-za-z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fa-f][0-9a-fa-f]))+', tubby) cleaned_url = urls[0].replace('?&autoplay=1', '') return cleaned_url def yt_id(code): the_id = code youtube_id = the_id.replace('https://www.youtube.com/embed/', '') return youtube_id def strip_hd(hd, move): str = hd new_hd = str.replace(move, '') return new_hd entries = [{'href': div.a.get('href'), 'text': strip_hd(strip_hd(div.h2.text, '– official video hd'), '– oficial video hd').lstrip(), 'embed': youtube_link(div.a.get('href')), #embed 'comments': strip_hd(strip_hd(div.h2.text, '– official video hd'), '– oficial video hd').lstrip(), 'src': 'https://i.ytimg.com/vi/' + yt_id(youtube_link(div.a.get('href'))) + '/maxresdefault.jpg', #image 'name': name, 'url': div.a.get('href'), 'author': author, 'video': true } div in video_row][:13] entry in entries: post = post() post.title = entry['text'] title = post.title if not post.objects.filter(title=title): post.title = entry['text'] post.name = entry['name'] post.url = entry['url'] post.body = entry['comments'] post.image_url = entry['src'] post.video_path = entry['embed'] post.author = entry['author'] post.video = entry['video'] post.status = 'draft' post.save() post.tags.add("video", "musica") return entries
my_addqueue.py
from rq import queue redis import redis .my_scraps import p_panties redis_con = redis() q = queue('important', connection=redis_con) task = q.enqueue(p_panties()) print('noted')
how fix this?
edit file structure
Comments
Post a Comment