how to send a message from google form to a python

Solutions on MaxInterview for how to send a message from google form to a python by the best coders in the world

showing results for - "how to send a message from google form to a python"
Hannes
04 May 2016
1import urllib.request
2from bs4 import BeautifulSoup
3import requests, warnings
4def get_questions(in_url):
5    res = urllib.request.urlopen(in_url)
6    soup = BeautifulSoup(res.read(), 'html.parser')
7    get_names = lambda f: [v for k,v in f.attrs.items() if 'label' in k]
8    get_name = lambda f: get_names(f)[0] if len(get_names(f))>0 else 'unknown'
9    all_questions = soup.form.findChildren(attrs={'name': lambda x: x and x.startswith('entry.')})
10    return {get_name(q): q['name'] for q in all_questions}
11def submit_response(form_url, cur_questions, verbose=False, **answers):
12    submit_url = form_url.replace('/viewform', '/formResponse')
13    form_data = {'draftResponse':[],
14                'pageHistory':0}
15    for v in cur_questions.values():
16        form_data[v] = ''
17    for k, v in answers.items():
18        if k in cur_questions:
19            form_data[cur_questions[k]] = v
20        else:
21            warnings.warn('Unknown Question: {}'.format(k), RuntimeWarning)
22    if verbose:
23        print(form_data)
24    user_agent = {'Referer':form_url,
25                  'User-Agent': "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36"}
26    return requests.post(submit_url, data=form_data, headers=user_agent)
Annaelle
02 Jul 2020
1import urllib
2import urllib2
3
4user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'
5header={'User-Agent' : user_agent}
6url = "http://....Your google form"
7# values from your form. You will need to include any hidden variables if you want to..
8values= {
9'entry.asdfsdfsdasd': 'asdfasdfsd',
10'draftResponse':'[,,"-asdfasdasdf"]',
11'pageHistory':'0',
12'fbzx':'-asdfasdfsd'
13}
14data = urllib.urlencode(values)
15urllib2.Request(url, data, header)