Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import feedparser
import requests
from gtts import gTTS
from bs4 import BeautifulSoup
import schedule
import time
import moviepy.editor as mp
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
from parrot import Parrot
from datetime import datetime
import shutil
# RSS URL'leri
RSS_URLS = {
'CNN': 'http://rss.cnn.com/rss/cnn_topstories.rss',
'NYTimes': 'https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml'
}
LAST_TITLES = {}
DAILY_VIDEO_COUNT = 0
MAX_DAILY_VIDEOS = 45 # Günlük maksimum 45 video
# YouTube API Key
YOUTUBE_API_KEY = 'YOUR_YOUTUBE_API_KEY'
# Parrot paraphrasing model
parrot = Parrot()
# Haberleri kontrol etme ve işleme
def check_news():
global LAST_TITLES, DAILY_VIDEO_COUNT
# Eğer günlük sınır aşıldıysa hiçbir şey yapma
if DAILY_VIDEO_COUNT >= MAX_DAILY_VIDEOS:
print("Günlük video sınırına ulaşıldı.")
return
for source, rss_url in RSS_URLS.items():
feed = feedparser.parse(rss_url)
latest_entry = feed.entries[0]
# Eğer yeni bir haber varsa
if LAST_TITLES.get(source) != latest_entry.title:
LAST_TITLES[source] = latest_entry.title
print(f"Yeni haber bulundu: {latest_entry.title} ({source})")
# Haber başlığıyla dizin oluştur
safe_title = "".join(x for x in latest_entry.title if x.isalnum() or x in "._- ")
dir_name = os.path.join(os.getcwd(), safe_title)
os.makedirs(dir_name, exist_ok=True)
# Haberi indir ve metin içeriğini al
response = requests.get(latest_entry.link)
soup = BeautifulSoup(response.content, 'html.parser')
article_text = get_clean_text(soup, source)
# Metni yeniden yazma
rewritten_text = paraphrase_text(article_text)
# AI News selamlaması ekle
intro_message = "AI News iyi günler diler. Today's top news is:"
full_text = intro_message + "n" + rewritten_text
# Metni seslendir
tts = gTTS(full_text, lang='en')
audio_path = os.path.join(dir_name, "news_audio.mp3")
tts.save(audio_path)
print(f"Ses dosyası kaydedildi: {audio_path}")
# Video ve resimleri indir
download_media(soup, dir_name)
# Video oluştur
create_video(audio_path, dir_name)
# YouTube'a yükle
upload_to_youtube(dir_name, latest_entry.title)
# Günlük video sayısını artır
DAILY_VIDEO_COUNT += 1
print(f"Günlük video sayısı: {DAILY_VIDEO_COUNT}")
# Metni yeniden yazan fonksiyon
def paraphrase_text(text):
paraphrased_sentences = parrot.augment(input_phrase=text)
return paraphrased_sentences[0][0] if paraphrased_sentences else text
# Metin içeriğini temizleme
def get_clean_text(soup, source):
if source == 'CNN':
article_body = soup.find('div', {'class': 'l-container'}) # CNN'deki içerik div'i
elif source == 'NYTimes':
article_body = soup.find('section', {'name': 'articleBody'}) # NYT makale içerik kısmı
if article_body:
for script in article_body(["script", "style", "header", "footer", "button", "nav"]):
script.decompose()
return article_body.get_text(separator=' ', strip=True)
return "Haber metni bulunamadı."
# Medyaları indirme
def download_media(soup, dir_name):
images = soup.find_all('img')
for i, img in enumerate(images):
img_url = img.get('src')
if img_url and img_url.startswith('http'):
img_data = requests.get(img_url).content
with open(os.path.join(dir_name, f'image_{i}.jpg'), 'wb') as handler:
handler.write(img_data)
# Video oluşturma
def create_video(audio_path, dir_name):
clips = []
for img_file in os.listdir(dir_name):
if img_file.endswith(".jpg"):
img_path = os.path.join(dir_name, img_file)
img_clip = mp.ImageClip(img_path, duration=3)
clips.append(img_clip)
audio_clip = mp.AudioFileClip(audio_path)
video = mp.concatenate_videoclips(clips)
video = video.set_audio(audio_clip)
video_path = os.path.join(dir_name, "news_video.mp4")
video.write_videofile(video_path, fps=24)
print(f"Video kaydedildi: {video_path}")
# YouTube'a yükleme
def upload_to_youtube(dir_name, title):
credentials = Credentials.from_authorized_user_file('credentials.json', ['https://www.googleapis.com/auth/youtube.upload'])
youtube = build('youtube', 'v3', credentials=credentials)
video_path = os.path.join(dir_name, "news_video.mp4")
body = {
'snippet': {
'title': title,
'tags': generate_tags(title),
},
'status': {
'privacyStatus': 'public'
}
}
media = MediaFileUpload(video_path, mimetype='video/mp4')
# YouTube'a video yükleme işlemi
response = youtube.videos().insert(
part="snippet,status",
body=body,
media_body=media
).execute()
# Video yükleme başarılıysa dizini sil
if response:
print(f"Video başarıyla yüklendi: {title}")
shutil.rmtree(dir_name) # Dizini ve içindeki tüm dosyaları sil
print(f"Dizin silindi: {dir_name}")
else:
print(f"Video yükleme başarısız: {title}")
# Tag oluşturma (en sık geçen kelimeler)
def generate_tags(text):
words = text.split()
tags = [word for word in set(words) if len(word) > 4][:20]
return tags
# Günlük sınırı sıfırlamak için her gün gece yarısı çalıştırılacak fonksiyon
def reset_daily_video_count():
global DAILY_VIDEO_COUNT
DAILY_VIDEO_COUNT = 0
print("Günlük video sayısı sıfırlandı.")
# Programı 5 dakikada bir çalıştır
schedule.every(5).minutes.do(check_news)
schedule.every().day.at("00:00").do(reset_daily_video_count)
while True:
schedule.run_pending()
time.sleep(1)
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team