<commit_before>//
//  Tweet.swift
//  tweetor
//
//  Created by admin on 04.05.17.
//  Copyright © 2017 spp. All rights reserved.
//

import Foundation
import SwiftyJSON

final class Tweet: NSObject, ResponseCollectionConvertible, ResponseConvertible {
    
    var identifier: String = ""
    var text: String = ""
    var timestamp: String = ""
    var user: User? = nil
    
    var latitude: Double = 0.0
    var longitude: Double = 0.0
    
    static func collection(_ responseData: JSON) -> [Tweet] {
        var tweets = Array<Tweet>()
        for (_,tweetData):(String,JSON) in responseData {
            tweets += [Tweet(responseData: tweetData)]
        }
        return tweets
    }
    
    init(responseData: JSON) {
        identifier = responseData["id_str"].string ?? ""
        
        let dateString = responseData["created_at"].string
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "ccc LLL dd HH:mm:ss Z yyyy"
        let date = dateFormatter.date(from: dateString!)
        dateFormatter.dateStyle = .medium
        dateFormatter.timeStyle = .medium
        timestamp = dateFormatter.string(from: date!)
        
        text = responseData["text"].string ?? ""
        
        user = User(userData: responseData["user"])
        
        if responseData["geo", "coordinates"] != JSON.null {
            latitude = responseData["geo", "coordinates", 0].double!
            longitude = responseData["geo", "coordinates", 1].double!
        }
    }
}<commit_msg>feat: enhance tweet model, add media<commit_after>//
//  Tweet.swift
//  tweetor
//
//  Created by admin on 04.05.17.
//  Copyright © 2017 spp. All rights reserved.
//

import Foundation
import SwiftyJSON

final class Tweet: NSObject, ResponseCollectionConvertible, ResponseConvertible {
    
    var identifier: String = ""
    var text: String = ""
    var timestamp: String = ""
    
    var mediaURL: String = ""
    var mediaType: String = ""
    
    var user: User? = nil
    
    var latitude: Double = 0.0
    var longitude: Double = 0.0
    
    static func collection(_ responseData: JSON) -> [Tweet] {
        var tweets = Array<Tweet>()
        for (_,tweetData):(String,JSON) in responseData {
            tweets += [Tweet(responseData: tweetData)]
        }
        return tweets
    }
    
    init(responseData: JSON) {
        identifier = responseData["id_str"].string ?? ""
        
        let dateString = responseData["created_at"].string
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "ccc LLL dd HH:mm:ss Z yyyy"
        let date = dateFormatter.date(from: dateString!)
        dateFormatter.dateStyle = .medium
        dateFormatter.timeStyle = .medium
        timestamp = dateFormatter.string(from: date!)
        
        text = responseData["text"].string ?? ""
        
        if responseData["extended_entities", "media", 0] != JSON.null {
            switch responseData["extended_entities", "media", 0, "type"].string! {
                case "photo":
                    mediaType = "photo"
                    mediaURL = responseData["extended_entities", "media", 0, "media_url_https"].string!
                case "video":
                    mediaType = "video"
                    mediaURL = responseData["extended_entities", "media", 0, "video_info", "variants", 0, "url"].string!
                default:
                    mediaType = "none"
            }
        }
        
        user = User(userData: responseData["user"])
        
        if responseData["geo", "coordinates"] != JSON.null {
            latitude = responseData["geo", "coordinates", 0].double!
            longitude = responseData["geo", "coordinates", 1].double!
        }
    }
}
{'fraction_non_alphanumeric': 0.11995725353994123, 'fraction_numerical': 0.009885118888592039, 'mean_word_length': 2.148864592094197, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1735530', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1030, 'n_words': 263}