Hi, Instead of doing everything by hand I would recommend doing a custom management command in Django.
Because management commands live inside Django ecosystem you get full benefits of Django. Migrations to setup database tables from model definitions. Models and ORM to interact with database. (Model)forms to validate your incoming data etc. Also I really suggest that you do the official tutorial from the docs to get hang of basic django concepts. ma 20. elok. 2018 klo 19.59 Mikko Meronen <mikkovillemero...@gmail.com> kirjoitti: > Hi and thanks for your help. > > I have tried postgress and now I have a problem using it. Here's my code > following an error. I appreciate any help. > > def do(): > x = 1 > while x == 1: > create_table() > print('finding data') > find_data() > time.sleep(120) > > def create_table(): > c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT, > published TEXT, UNIQUE(url))') > > def find_data(): > r = requests.get(homepage) > soup = BeautifulSoup(r.text, 'html.parser') > results = soup.find_all('data') > for result in results: > title = result.find('h1').text > url = result.find('a')['href'] > published = result.find('time')['datetime'] > > > c.execute("INSERT OR IGNORE INTO testi (url, title, > published) VALUES (%s, %s, %s)", > ('url', 'title', 'published')) > connection.commit() > > > do() > > ERROR: > > Traceback (most recent call last): > File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 43, in > <module> > do() > File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 21, in > do > find_data() > File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 39, in > find_data > ('url', 'title', 'published')) > *psycopg2.ProgrammingError: syntax error at or near "OR"* > *LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES (...* > > > > -Mikko > > > 2018-08-17 19:09 GMT+03:00 Mikhailo Keda <mriy...@gmail.com>: > >> You could generate models from sqlite database - >> https://docs.djangoproject.com/en/2.1/howto/legacy-databases/ >> Than switch to PostgresQL >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/52f5c754-7310-4baa-8008-edbcea15eafb%40googlegroups.com >> <https://groups.google.com/d/msgid/django-users/52f5c754-7310-4baa-8008-edbcea15eafb%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAGD0jjJof7v9nMPF593DJiQHRv6z_%3DmQ_ZtQWob47PBT1gvL9Q%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAGD0jjJof7v9nMPF593DJiQHRv6z_%3DmQ_ZtQWob47PBT1gvL9Q%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHn91oex8cAE1yFshSABt9QZpdiiRVtALtLx0AWDNU84w0%2Bqvw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.