Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import os
- import re
- import pymysql
- import Config
- import requests
- from os.path import isfile, join
- from shutil import copyfile
- from pprint import pprint
- DB_HOST = '140.118.70.162'
- DB_USER = 'jobguide'
- DB_PASSWD = 'zNW3hw1HjMsQvOc9'
- DB_NAME = 'jobguide'
- DB = pymysql.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWD, db=DB_NAME, port=13306, charset='utf8')
- CURSOR = DB.cursor()
- SQL = "INSERT INTO ptt_articles(title, author, board, content, date, ip, article_uuid) VALUES (%s, %s, %s, %s, %s, %s, %s)"
- def main():
- """
- file = open("job-200-300.json", 'r')
- lines = file.readlines()
- lines[0] = '[\n'
- lines[len(lines) - 1] = '}\n]'
- file.close()
- file = open("job-200-300_update.json", 'w')
- file.writelines(lines)
- file.close()
- """
- with open('job-200-300_update.json','r') as json_file:
- data = json.loads(json_file.read())
- date_time = format_date(data[0]['date'])
- CURSOR.execute(SQL, (data[0]['article_title'],
- data[0]['author'],
- data[0]['board'],
- data[0]['content'],
- date_time,
- data[0]['ip'],
- data[0]['article_id'] ))
- #json_data[0]['date'][0] = ' '
- """
- for data in json_data:
- print (data['author'])
- """
- def format_date(datetime):
- temp = datetime.split(' ')
- format_datetime = '%s-%s-%s %s' %(temp[4], month(temp[1]), temp[2], temp[3])
- return format_datetime
- def month(month):
- return{
- 'Jan' : '01',
- 'Feb' : '02',
- 'Mar' : '03',
- 'Apr' : '04',
- 'May' : '05',
- 'Jun' : '06',
- 'Jul' : '07',
- 'Aug' : '08',
- 'Sep' : '09',
- 'Oct' : '10',
- 'Nov' : '11',
- 'Dec' : '12'
- }[month]
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement