def write_to_csv(data): with open('database.csv', mode='a') as db2: email = data["email"] subject = data["subject"] message = data["message"] csv_w = csv.writter(db2, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) csv_w.writerow([email, subject, message])
def write_to_csv(data): with open('database.csv', mode='a') as database2: email = data["email"] subject = data["subject"] message = data['message'] csv_writter = csv.writter(database2, delimiter=',', newline='', quotechar='|', quoting=csv.QUOTE_MINIMAL) csv_writter.writerow([email, subject, message])
def report(request): """ This report view is to report a csv file contains all the counter data Only can viewed by staff members """ title = " Click-through Data " if request.POST: form = DownloadResponseForm(request.POST) if form.is_valid(): start_date = form.cleaned_data['start_date'] end_date = form.cleaned_data['end_date'] + timedelta(days=1) our_timezone = pytz.timezone(settings.TIME_ZONE) start_date_tz = our_timezone.localize(datetime.combine(start_date, datetime.min.time())) end_date_tz = our_timezone.localize(datetime.combine(end_date, datetime.min.time())) counters = Counter.objects.filter(timestamp__lt=end_date_tz,timestamp__gte=start_date_tz) filename = "Report Click-through data from " + start_date.strftime("%Y-%m-%d") + " to " + end_date.strftime("%Y-%m-%d") http_response = HttpResponse() http_response = HttpResponse(content_type='text/csv') http_response['Content-Disposition'] = 'attachment; filename="%s.csv"' % (filename) writer = csv.writter(http_response) header = ["url", "timestamp"] writer.writerow(header) for counter in counters: csv_row = [] csv_row.append(counter.url) csv_row.append(localtime(counter.timestamp).strftime("%Y-%m-%d %H:%M:%S")) writer.writerow(csv_row) return http_response else: form = DownloadResponseForm() return render(request, "admin/download_csv.html", { "form" : form, "title" : title, })
def export_to_csv(modeladmin, request, queryset): opts = modeladmin.model._meta response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename={}.csv'.format(opts.verbose_name) writer = csv.writter(response) fields = [field for field in opts.get_fields() if not field.many_to_many and not field.one_to_many] # Write a first row with header information writer.writerow([field.verbose_name for field in fields]) # Write data rows for obj in queryset: data_row = [] for field in fields: value = getattr(obj, field.name) if isinstance(value, datetime.datetime): value = value.strftime('%d/%m/%Y') data_row.append(value) writer.writerow(data_row) return response
def butler(self): import subprocess from textblob import TextBlob subprocess.call(["afplay", "Submarine.aiff"]) self.label['text'] = "Litsening .......!" import speech_recognition as sr r = sr.Recognizer() with sr.Microphone() as source: self.label['text'] = "Speak out Your Command!" audio = r.listen(source) try: self.label['text'] = r.recognize_google(audio) words = TextBlob(r.recognize_google(audio)) date = dt.datetime.now() sentence = r.recognize_google(audio) learn = [date, sentence.encode("utf-8")] with open('brain.csv', 'w') as f: writer = csv.writter(f) writer.writerow(['date', 'sentence']) writee.writerows(learn) a = words.words for i in a: if i == "music": os.system('say "playing music!" ') self.musicplayer() elif i == "remind" and i == "tomorrow": os.system('say "Adding an event to your schedule"" ') self.reminder_tomorrow(a) except sr.UnknownValueError: self.label['text'] = "Sorry i cant understand you!" os.system('say "Sorry i cant understand you!" ') except sr.RequestError as e: self.label['text'] = e os.system('say "Could not esctablish an internet connection" ') self.offlineservice()
import requests from bs4 import BeautifulSoup import csv source=requests.get('https://coreyms.com/').text #print(source.status_code) soup=BeautifulSoup(source,'lxml') #print(soup.prettify()) csv_file=open('output.csv','w') csv_writter=csv.writter(csv_file) csv_writter.writerow(['Headline','Summary','Youtube Link']) for article in soup.find_all('article'): #print(article.prettify()) headline=article.a.text print(headline) summary=article.find('div',class_='entry-content').p.text print(summary) try: video_src=article.find('iframe',class_='youtube-player')['src'] video_id=video_src.split('/')[4] video_id=video_id.split('?')[0] # print(video_id) youtube_link = f'https://youtube.com/watch?v={video_id}' except Exception as e: youtube_link='NONE' print(youtube_link) print()
def wriiter_csv(data): with open('lalafo.csv', 'a') as f: writter = csv.writter(f) writter.writerow((data['title'], data['url'], data['price']))
input_file = r"C:\Users\aN_v_M__\Desktop\python\RH_Assets_Threats_points_updated_July_2019.csv" data = csv.reader()(open(input_file), delimiter = ',') data = list(csv.reader()(open(input_file), delimiter = ',')) for row in data: newline = [item.strip() for item in row] newline = [item.title() for item in newline] newdata.append(newline) newdata = [] for row in data: newline = [item.strip() for item in row] newline = [item.title() for item in newline] newline = [newline[].replace("Pentecoste", "Pentecostal")] infile_name = os.path.splitext(input_file)[0] infile_ext = os.path.splitext(input_file)[1] outfile = ("{}{}{}".format(infile_name, '_cleaned', infile_ext)) writer = csv.writter(open(outfile, 'w'), deli) #adding new items #rstyjuhi
def save(self, obj): with open ("Pb.csv", 'wt') as f: w = csv.writter(f) for row in Pb.items(): w.writerow(row)