Advertisement
Guest User

Untitled

a guest
Apr 8th, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import time
  2. import datetime
  3. import json
  4. import requests
  5.  
  6. #so luong post trong 1 ngay
  7. posts_per_day = 100
  8. #so ngay bi gioi han
  9. slow_day = 30
  10.  
  11. with open('extracted.txt') as articles:
  12. #load data bai viet tu file json
  13. articles = json.loads(articles.read())
  14. day = 0
  15. x = 0
  16. for article in articles:
  17. now = datetime.datetime.today()
  18. x += 1
  19.  
  20. if x%posts_per_day == 0:
  21. day += 1
  22.  
  23. if day > slow_day:
  24. timedelta = now + datetime.timedelta(days=slow_day)
  25. else:
  26. timedelta = now + datetime.timedelta(days=day, minutes=x)
  27.  
  28. publish_time = timedelta.strftime("%Y-%m-%d %H:%M:%S")
  29.  
  30. data = {'title': article['title'], 'content': article['content'], 'publish_time': str(publish_time)}
  31. #connect den url va thuc hien post du lieu
  32. r = requests.post('http://localhost/site/api/', data = data)
  33. #print(day)
  34. print('Status: ' + str(r.status_code))
  35. print(article['title'])
  36. print(publish_time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement