Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import datetime
- import json
- import requests
- #so luong post trong 1 ngay
- posts_per_day = 100
- #so ngay bi gioi han
- slow_day = 30
- with open('extracted.txt') as articles:
- #load data bai viet tu file json
- articles = json.loads(articles.read())
- day = 0
- x = 0
- for article in articles:
- now = datetime.datetime.today()
- x += 1
- if x%posts_per_day == 0:
- day += 1
- if day > slow_day:
- timedelta = now + datetime.timedelta(days=slow_day)
- else:
- timedelta = now + datetime.timedelta(days=day, minutes=x)
- publish_time = timedelta.strftime("%Y-%m-%d %H:%M:%S")
- data = {'title': article['title'], 'content': article['content'], 'publish_time': str(publish_time)}
- #connect den url va thuc hien post du lieu
- r = requests.post('http://localhost/site/api/', data = data)
- #print(day)
- print('Status: ' + str(r.status_code))
- print(article['title'])
- print(publish_time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement